Developer forum

Forum » Templates » Access to Product tags from Razor template

Access to Product tags from Razor template

Thomas Larsen
Reply

I an razor page template I would like to access product tage on varius products. I know I can get some of the information directly from the product class

How can I do that?

<div>

    @{

        foreach (var ProductID in ProductIDs)

        {

            var Product = Dynamicweb.eCommerce.Products.Product.GetProductByID(ProductID);

            <div>

                Name from class: @Product.Name

            </div>

        }

    }

</div>


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Thomas

In the layout template, you do nat have access to a product since it is not being rendered there.

If you render the product on the page already using a product template, you can, inside the product template, add properties to the pageview object like you would use a viewbag:

Pageview.Value("ProductPrice") = GetString("Ecom:Product.Price")

Then in your layout template you can use those information:

@Pageview.Value("ProductPrice")

 

You must be logged in to post in the forum