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.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

can I use Top in a control?

Go to End

8 Posts   3348 Views


Community Member, 178 Posts

22 September 2010 at 1:34pm

I have code as follows:

   <% control ImageResources %>
        <% if TopActive == ID %>
                <li>not showing the image with ID= $Top.Active</li>
        <% else %>
            <li>DATA= $Top.getActive ... $ID - test this style call</li>
            <li>DATA= $Top.Active ... $ID - test this style call</li>
                <li><a href="{$Top.Link}Display/{$ID}" >$Title</a></li>
                <li>caption: $Caption</li>
        <% end_if %>  
    <% end_control %>

I can't figure how I can use an if statement to compare the local ID and the ID from a level up.
You can see I have a couple test li, that show me that I am getting the Top.Active and ID, and I can see when they match.
I just can't get the template to like my conditional.

Please help.. this should be easy I would think.


Community Member, 473 Posts

22 September 2010 at 2:08pm

You can only compare against literals in ifs.


Community Member, 178 Posts

22 September 2010 at 2:42pm

Edited: 22/09/2010 2:42pm

OK, so does that mean I can pass the ID along to the method?
and can I use Top?

I found that the top. syntax causes an error.

I'm trying to get a sense of the limitations here..


Forum Moderator, 5523 Posts

22 September 2010 at 6:58pm

No you cannot pass any variables along to it. You need to contain any logic like that in the php class.


Community Member, 12 Posts

1 October 2010 at 5:56am

thanks for the tip.. took me a little to get my head wrapped around it but I'm there.

on a related note:
I am trying to use 'Top' to break out of a control, and am finding that I don't really get the data that I expect.
Is there a clear definition of what using 'top' really does?
I have tested it in a number of cases, and it doesn't seem to give you access to the data outside the control but rather to the base of the template.
Is there another way to reference data outside a control other than writing custom methods to return the data?


Community Member, 178 Posts

18 November 2010 at 7:50am

Where might I find 'top' in the api docs?

Is there any other similar command that will breakout of a number of controls?

I mean it would be handy to be able to say $break(1).title if you wanted to output the title of a dataobject that you are using in a control while you are also controlling image (so that you can use the image methods).
Being able to break out 1 level would be great, but if you could break out a defined number that would be outstanding.
Currently the only similar feature seems to be top, but that doesn't help if I want data related to the dataobject that I'm in.


Forum Moderator, 5523 Posts

18 November 2010 at 3:29pm

Top will always go to the Top most scope. Its a function on every ViewableData object. You can see the method (but no docs) here

You cannot currently go $Parent or $Back to break out of just 1 loop. This was a recent discussion on the core mailing list. Check that out for all the discussion and possible solutions.


Community Member, 178 Posts

19 November 2010 at 7:04am

Thanks, I was browsing the api and found toplevel() but not viewable data, still working on getting a full understanding of the structure of the system, I guess it will only come with time, however I am getting a sense of how I might be able to write a short tutorial to show beginners how they can use the api docs to locate additional methods. Do you think that this would be well received?

I found this post that has helped me with my problem somewhat:

Where would I find the core mail-list to read up on the discussion you mentioned?