Developer forum

Forum » Development » Typed object in custom module frontend

Typed object in custom module frontend

Alec Stubbs
Reply

Hi folks,

 

I've recently started using DW 8.6 after being stuck on 8.3 for ages and wanted to know if any progress has been made towards enabling a typed object to be passed to a custom modules template from the frontend class in a similar way to how a Model is passed from a controller to a view in an MVC app?

 

Cheers,

Alec


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Alec

You can do that in various ways.

The template class actually have a hidden method that can be used to pass objects to the rendering engine:

Tempalte.SetTemplateValue("MyModelName", eCommerce.Products.Product.GetProductByID("Prod1"))

When you do that, you can access the object from your Razor template using GetValue:

​(eCommerce.Products.Product.GetProductByID)product = GetValue("MyModelName");

​If your template is a HTML version, that tag would return the value of the objects ToString()

You can also use the PageView - it has something that is more or less the same as the ViewBag/ViewData:

In your code do something like this:

PageView.Current.set_Value("MyModelName", eCommerce.Products.Product.GetProductByID("Prod1"));

When you do that, you can access the object from your Razor template using get_Value:

​(eCommerce.Products.Product.GetProductByID)product = PageView.Current.get_Value("MyModelName");

Votes for this answer: 1
 
Alec Stubbs
Reply

Thanks Nicolai this sounds interesting.

 

You must be logged in to post in the forum