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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Using Variable in loop after Up


Go to End


3 Posts   1945 Views

Avatar
theTigerDuck

Community Member, 20 Posts

19 July 2013 at 10:35pm

Hi I try to do something like this in Template:

<% loop getAllCategories %>
     <h1>$Category</h1> <!-- this is Correct -->
     <% loop Up.getFurnitureByCategory($Category) %>
       //content here
     <% end_loop %>
<% end_loop %>

In getFurnitureByCategory I don't get the Category, instead I get and string "$Category".

I also tried escaping like {$Category}, but then I the braces are just part of my string.
And $Me.Category didn't work either.

Avatar
kinglozzer

Community Member, 187 Posts

20 July 2013 at 3:22am

As soon as you use $Up, you take it out of the category scope, so you can't use $Category like that as it doesn't exist in your current scope.

From what you're doing, I think you'd be better off using a GroupedList: http://doc.silverstripe.org/framework/en/howto/grouping-dataobjectsets

Avatar
theTigerDuck

Community Member, 20 Posts

20 July 2013 at 3:28am

Edited: 20/07/2013 3:38am

Ahh ok, many thanks I'll have a look at this.

Edit: cool thats pretty easy, works best many thanks again.