I like the #2 better, if only as I want to do more than class body with front/non-front, i.e., the first term in a path as in my example. Using a call to a macro is easier to manage than inline code. HOWEVER, nodetypealias is returning the doctype used, not whether it's the front page for the site.
It is not deprecated as such as it depends if you are querying the node using XPath in XSLT or via the API. It should have read NodeTypeAlias and as we are using the API and Razor in the above examples it is applicable.
I used the Document Type Alias as an example of how to work out if its the homepage because generally you will only every use a single doctype to represent your homepage. Another option could be to test against the Level property of a document.
@Model.Level == 1
But again this entirely depends on how you have structured your tree.
Classing the body tag by URL path
I'd like to have the ability to class my body tag depending on the current URL. Thus:
http://www.example.com would render
http://www.example.com/section/landing would render:
Where to start? Thanks!
Your options could be as follows.
1: You could write a small piece of inline C# to achieve this by looking at what the docmenttype is for the current page.
2: Write a small razor macro to work it out. The razor code would look something like this
and then on the page in the body tag
It seems that .Nodetypealias was depreciated in 4.5? http://bit.ly/M01HZm
I like the #2 better, if only as I want to do more than class body with front/non-front, i.e., the first term in a path as in my example. Using a call to a macro is easier to manage than inline code. HOWEVER, nodetypealias is returning the doctype used, not whether it's the front page for the site.
It is not deprecated as such as it depends if you are querying the node using XPath in XSLT or via the API. It should have read NodeTypeAlias and as we are using the API and Razor in the above examples it is applicable.
I used the Document Type Alias as an example of how to work out if its the homepage because generally you will only every use a single doctype to represent your homepage. Another option could be to test against the Level property of a document.
But again this entirely depends on how you have structured your tree.
Oops; double post.
I just had my first coding experience with Razor. Here's the result:
I'll still need to split and get the first arg from the "model.level" section, i.e.,
Rendering:
that's to come when I have more nested pages.
Thanks!
is working on a reply...