Developer forum

Forum » Templates » Can not access template tags inside cart html

Can not access template tags inside cart html

Davor Zlotrg
Reply

On the cart page (in the template that is attached on the paragraph module) I can not access any of the template tags.

Here is the example

http://belugi.dw.inet-design.dk/cart

 

Inside ShowCart_Compact.html I should be able to output <!--@Item.Area.Checkout_Page_ID--> but it returns the empty string. From the master template (which is converted to razor it works just fine - you can see when you scroll down).

 

Can you see what's wrong with my code?


Replies

 
Nicolai Høeg Pedersen
Reply

You cannot access template tags from one context (Layout template where Item.Area.* tags belong) in another template, like the cart. You can only use Global tags accross templates.

If using Razor, you can however put the value from the template tag in the items collection and use it in other templates:

In layout template:

System.Web.HttpContext.Current.Items["MyVar"] = GetString("Item.Area.*");

In cart template:
var myVar = System.Web.HttpContext.Current.Items["MyVar"];

BUT - this will only work if the part in the layout template is being executed before it is executed in the cart template.

An alternative is in the cart template to access the area item directly using the API:

object myvar = null;
Dynamicweb.Frontend.PageView.Current().Area.Item.TryGetValue("ItemFieldSystemName", ref myvar);

 
Davor Zlotrg
Reply

But how does it work on the Solutionset we downloaded from http://developer.dynamicweb.com/downloads.aspx

It is the same code, the only change was that we converted Main.html to razor syntax?

 

This demo version is published on http://dw.inet-design.dk/en-US/Cart.aspx and I see that the template tag is rendered just fine.

 
Nicolai Høeg Pedersen
Reply

Hi Davor

There is some relatively big differences in how Razor and HTML templates work. It is actually a bug/coinicidence that it works using HTML templates.

 

You must be logged in to post in the forum