Hiya,
I've got an interesting one.
Our client is using an external IP library to determine WHERE a user is coming from.
Some of the content changes depending on what this location is. This is working fine on these three page types:
Page
RegionalPage (extends page, with one additional dropdown to select which region is allowed to see it)
The problem I am having is how to filter the navigation based on the chosen value in the dropdown filed on the RegionalPage type.
Here is the HTML for the menus:
<div id="main-nav">
<ul id="nav">
<% control Menu(1) %>
<li><a href="$Link" title="Go to the "{$Title}" page" class="$LinkingMode"><span>$MenuTitle</span></a>
<% if Children %>
<ul>
<% control Children %>
<li><a href="$Link" title="Go to the "{$Title}" page" class="$LinkingMode"><span>$MenuTitle</span></a></li>
<% end_control %>
</ul>
<% end_if %>
</li>
<% end_control %>
</ul>
</div>
What I need to be able to do is under the <% control Children %> control, I need to be able to check if that particular child is allowed to be displayed in the menu.
I have tried doing this a number of ways, but the most logical for me seems to be to add a new method to the page controllers for both page types like so:
function RegionMatch() {
// Code to check ip location in a cookie and this page's current region setting
return true; // DEBUG - always return true
}
And adjust my template to this:
<div id="main-nav">
<ul id="nav">
<% control Menu(1) %>
<li><a href="$Link" title="Go to the "{$Title}" page" class="$LinkingMode"><span>$MenuTitle</span></a>
<% if Children %>
<ul>
<% control Children %>
<% if RegionMatch %>
<li><a href="$Link" title="Go to the "{$Title}" page" class="$LinkingMode"><span>$MenuTitle</span></a></li>
<% end_if %>
<% end_control %>
</ul>
<% end_if %>
</li>
<% end_control %>
</ul>
</div>
When I do this however, that function is never being called (as it is not returning true), none of the Children appear despite the default return value being true for now.
Any ideas on how this could be achieved? Either this way or another.
Cheers
Aaron