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.

General Questions /

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

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

Using Variable in loop after Up


Reply


3 Posts   322 Views

Avatar
tekilla83

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, 167 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
tekilla83

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.