3217 Posts in 853 Topics by 812 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1726 Views |
-
Accessing variables inside nested controls

8 June 2010 at 10:46am
Hey Everyone,
Is there anyway I can access variables from inside nested Controls? Its probably easier to explain it using a few code snippets. The below code works and does pretty much what you'd expect. It prints out a list of venues then a list of campaigns for each venue and then a list of products for each campaign.<% control Entities %>
<h3>$EntityName</h3>
<% control Campaigns %>
<h4><a href="/browse-campaigns/view/$ID">$Name</a></h4>
<% control Products %>
<h5>$Name - $Count</h5>
<% end_control %>
<% end_control %>
<% end_control %>This works, but I don't really want it to be structured hierarchically like this instead I would just like a plain list of products, but I also want to output the variables for each entity and campaign. Basically I am trying to do something like the below. Is there any way to achieve this or am I better of changing the structure of the array data that I am using?
<% control Entities %>
<% control Campaigns %>
<% control Products %>
<h3>$Entities.Name</h3>
<h4><a href="/browse-campaigns/view/$Campaigns.ID">$Campaigns.Name</a></h4>
<h5>$Name - $Count</h5>
<% end_control %>
<% end_control %>
<% end_control %> -
Re: Accessing variables inside nested controls

21 June 2010 at 11:52pm Last edited: 21 June 2010 11:53pm
Have you tried $Parent.Name and / or $Top.Name ? The prior should be able to access the variable from the control one level up in your nested architecture. The latter should retrieve the variable from the (you guessed it) top-level of the template. But that would probably be looking outside all of the controls for the variable, where it won't be found.
So I think $Parent would be your best bet, although I'm not sure how that behaves when there are more than just two levels, seeing as you have three controls nested inside each other in your "ideal situation" example.
Good luck
-
Re: Accessing variables inside nested controls

13 June 2012 at 3:17am
No, $Top or $Parent doesn't work for me. Any other way??
| 1726 Views | ||
|
Page:
1
|
Go to Top |


