Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

ChildrenOf() Call


Reply

7 Posts   2987 Views

Avatar
brb5548

8 July 2008 at 6:15am Community Member, 17 Posts

Hi,
I am trying to use the ChildrenOf function and everything works great as long as I hard code the page-url value. Does anyone know if I can pass a parameter that represents the url of the current page instead of hard coding this value?

My goal is to create a menu bar that only shows the child pages and I am having a hard time.

Sample Code:
<% if Children %>
<h1>Menu</h1>
<div class="submenu">

<% control ChildrenOf(photos) %>

<a href="$Link" title="Go to the $Title.XML page" <% if LinkingMode %>class="$LinkingMode"<% end_if %>>$MenuTitle</a>   
         
<% end_control %>
</div>
<% end_if %>

Avatar
Hamish

8 July 2008 at 4:40pm Community Member, 712 Posts

Hey there,

To be clear - you want to control the children of the current page?

The standard: <% control Children %> should do the trick.

Avatar
brb5548

9 July 2008 at 12:48am (Last edited: 9 July 2008 1:02am), Community Member, 17 Posts

There seems to be a problem with just using the Children call. For example, if I layout several pages in a 2 or 3 level format like:
-Home
+News
+Calendar

When you click on the Home page you can see the Children call display the sub-pages properly. (News and Calendar) But when you click on the News page you will still have the sub-pages displayed of the Home page. (News and Calendar)
So it seems with 2nd and 3rd level pages, the Children call returns only the sub-links of the parent page. Here is the code that I am using during the above test.

<% control Level(1) %>

<% if Title = Blog %>
<% else %>
<% if Title = Forums %>
<% else %>

<% if Children %>
<h1>Menu</h1>
<div class="submenu">

<% control Children %>
<a href="$Link" title="Go to the $Title.XML page" <% if LinkingMode %>class="$LinkingMode"<% end_if %>>$MenuTitle</a>   
         
<% end_control %>
</div>

<% end_if %>
<% end_if %>
<% end_if %>

<% end_control %>

$SideBar
<% include Cart %>

Any ideas??

Avatar
dio5

9 July 2008 at 1:12am (Last edited: 9 July 2008 1:12am), Community Member, 501 Posts

That makes perfectly sense...

You're doing <% control Level(1) %>

So if you're layout is like

-Home
----News
----Calendar

With this code you're using - it will always fetch the 'home' subpages... because you're in level1 all the time... I think...

Avatar
brb5548

9 July 2008 at 1:32am Community Member, 17 Posts

That was my first thought so during my testing, I had that control level(1) line removed (I had to actually add it back in to my previous post with an edit)
What I found out is that you are correct and that control level needs to be removed and you have to nest the link iterations for each child control. The big thing that I was missing was a conditional check for LinkOrCurrent = current before each child control iteration.
The code below works but I was hoping to find a cleaner way. If someone comes across this post and has a better way to display only sub-page links to the current page, please let everyone know.
Thanks for the help.

<% if Title = Blog %>
<% else %>
<% if Title = Forums %>
<% else %>

<% if LinkOrCurrent = current %>

<% if Children %>
<h1>Menu</h1>
<div class="submenu">

<% control Children %>
<a href="$Link" title="Go to the $Title.XML page" <% if LinkingMode %>class="$LinkingMode"<% end_if %>>$MenuTitle</a>   

<% if LinkOrCurrent = current %>
<% if Children %>
<ul>
<% control Children %>
<li><a href="$Link" title="Go to the $Title.XML page" <% if LinkingMode %>class="$LinkingMode"<% end_if %>>$MenuTitle</a></li>
<% end_control %>
</ul>
<% end_if %>
<% end_if %>
<% end_control %>
</div>

<% end_if %>
<% end_if %>
<% end_if %>

<% end_if %>

$SideBar
<% include Cart %>

Avatar
dio5

9 July 2008 at 1:38am (Last edited: 9 July 2008 1:39am), Community Member, 501 Posts

All I usually need to do to show the children is

<% if Children %>
<% control Children %>
   <a href="$Link" title="Go to the $MenuTitle.ATT page" class="$LinkingMode">$MenuTitle.XML</a>
<% end_control %>
<% end_if %>

Avatar
Hamish

9 July 2008 at 7:59am Community Member, 712 Posts

Hey brb - just looking at the last piece of code you posted:

As far as I can see, the first <% if LinkOrCurrent = current %> should always evaluate to true, since you're always controlling the 'current' page by default (unless there are control statements elsewhere that we can't see).

Your second <% if LinkOrCurrent = current %> should always evaluate to false, since it's within a control statement for the children pages of the 'current' page (and because you've already checked that another page was 'current' earlier, and now you're controlling a different page -- it has to be false!)

That's just from eyeballing the code, but if you remove those pieces then you end up with exactly what dio posted.