Developer forum

Forum » Development » Developing Custom Modules with Razor Templates

Developing Custom Modules with Razor Templates

Ivo Rodrigues
Reply

Hello guys,

We have a LOT of custom modules that implement many complex operations on trasactional sites, in a SOA architectural context.

We still use the old html templates and I'm finding some time to start migrating them to Razor templates.

I've been searching everywere for some kind of a "howto migrate your custom modules into razor templates". I found this article, but I'm afraid it may be outdated (I need to know the Dynamicweb recommended way):

https://github.com/TryingToImprove/BlogStuff/blob/master/Proof%20Of%20Concept%20-%20Using%20Razor%20in%20a%20Custom%20DynamicWeb%20Module%20.md

Can you help me, please. My main concerns are:

1. How to load the razor template in the Dynamicweb.ContentModule.GetContent() method;

2. Can I still use the setTag() method, or must I place all the information rendered by the template on the @Model?

Thanks in advance,

Best Regards,

Ivo


Replies

 
Mikkel Ricky
Reply

If your custom module provides the user with a template selector (using a FileManager control) that allows selecting a Razor (cshtml) template then you don't have to change anything in your custom module. All that has to be done is selecting a Razor template in the module settings.

The values your module to a Template object using SetTag, GetLoop etc. are available for use in a Razor template using @GetValue, @GetLoop etc. The Template object ifself does not care if you're using an HTML or Razor template in the frontend.

See Getting started with Razor and From Dynamicweb HTML to Razor for more information on using Razor in Dynamicweb.

Best regards,
Mikkel

 

 
Morten Bengtson
Reply

What Mikkel said :)

The Model is basically an instance of Dynamicweb.Rendering.Template.

If you want, you CAN pass objects from your custom module to your razor template by using template.SetTagValue("myvalue", someobject); - but you don't have to. The object will only be available in a Razor template - it will be ignored if you use a regular html template.

 
Ivo Rodrigues
Reply

Thank you guys! I've already migrated one module with success.

Cheers,

Ivo

 
Nuno Aguiar
Reply

Hi Ivo,

 

Great to see you guys are upgrading the modules. A lot of new possibilities emerging wink

 

Nuno

 

You must be logged in to post in the forum