Developer forum

Forum » Templates » Razor syntax help - pageview.area.item loop

Razor syntax help - pageview.area.item loop

Rune Skovbo
Reply

Hi

I wanna loop through an area.itemlist on a productpage.

Im thinking something like:

                            @foreach (var function in GetLoop("Pageview.Area.Item['Item.Area.Funktioner']")){
                            
                                @function.TemplateTags();
                    
                            }

But its not working.

If I want a "non-looped" value, I do this: @Pageview.Area.Item["SizeGuide"]  - and it works.

 

The working loop on the master page looks like this:

        @foreach (var function in GetLoop("Item.Area.Funktioner")){
        
            @function.TemplateTags();

        }

My problems is using it on the product page.

 

Hope you can help.

/Rune 

 


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

Did you try this:

GetLoop("Item.Area.Funktioner")

instead?

Also, watch out for words like function. It may be a reserved word.

Cheers,

Imar

 
Rune Skovbo
Reply

Hi Imar

Fixed the "function", but it didn't help - but your right, it could easy be reserved.

Well this: 

                            @foreach (var myFunction in GetLoop("Item.Area.Funktioner")){
                            
                                @myFunction.TemplateTags();
                    
                            }

 

Works on the master page - but not on the product page.

Im pretty sure I need som @Pageview.Area.Item["xx"]  stuff to reach it, but im not sure.

 

/Rune

 
Mikkel Ricky
Reply
This post has been marked as an answer

Rune, you're on the right track with using Pageview.Area.Item. For the last piece of the puzzle, check out this post: http://developer.dynamicweb.com/forum/development/re-itemmanager-storage-getbyid-interate-through-itemlist.aspx#Reply38853

Best regards,
Mikkel

Votes for this answer: 1
 
Rune Skovbo
Reply

Hi Mikkel

Wow, that seams complex for a simple loop? At least for me on a monday...

Can you help me merge my item into it?

Thanks  a lot!

/Rune

 
Mikkel Ricky
Reply

Try copying the pieces from the other post into your template, replace item["Indhold"] with Pageview.Area.Item["Funktioner"] and replace «item type of item list items» with the actual system name of the item in your list. 

Best regards,
Mikkel

 
Rune Skovbo
Reply

Thanks, thats how far I got as well :-)

Now when i try do i.GetValue("XX") in the loop, I get this message:

"

Dynamicweb.Content.Items.Item' does not contain a definition for 'GetValue' and no extension method 'GetValue' accepting a first argument of type 'Dynamicweb.Content.Items.Item' could be found (are you missing a using directive or an assembly reference?)

"

/Rune

 
Mikkel Ricky
Reply

The items you have inside the loop are not template loop items, "real" items and therefore you have to write 

@item["XX"]

to get values from the item.

Best regards,
Mikkel

 
Rune Skovbo
Reply

So, this is what I have now:

@foreach (var i in GetItems(Pageview.Area.Item["Funktioner"] as string, "Funktion"))
{
    @item["Billede"]
}

But I guess I still have to declare if I want a value, a string or what not?

The above is not working, I get this:

"

'Dynamicweb.Content.Items.Item' is a 'type' but is used like a 'variable'

"

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

You want  @i["Billede"] instead of  @item["Billede"] as that's the variable in the loop.

Imar

 
Rune Skovbo
Reply

Of course! Thanks!

Now it works like a charm.

Thanks guys!

/Rune

 

You must be logged in to post in the forum