In my last post I had discussed about Razor in Umbraco. Now let me share more about the implementation part of Razor in Umbraco. As we know Razor can be used in scenarios where we had used XSLT.
Here I would like to use Razor syntax to access document property data in Umbraco. We have a variable called @Model in Razor which is equivalent to the $currentPage in XSLT. Similarly we can use Razor to access all the properties like .Name , .Url ,.Level , .Id etc using @Model. Also we have option to access the custom property associated with a document type.
We can write Razor syntax in two modes i.e. Inline Razor approach or dedicated approach. Inline Razor approach is the style of writing the Razor syntax in line with the HTML snippets inside a template. While dedicated Razor approach refers to the style of writing Razor snippets separately under the scripting files. Then we associate this to a Macro and insert it onto the template.
Let me write a Razor snippet to access the property data in Umbraco, it will display the Name and Url of the page.
Now similarly we can access the Custom properties as well. Let’s have the following code snippet which access a Custom property called “myProperty”
So we have learned a bit on how to access property data using Razor syntax. I believe all C# folks would like this approach as they can do the similar things as fast as it is done in XSLT approach.
No comments:
Post a Comment