Razor - Check for document type and create if statement
Hi
I need some help on how to check for a specific document type in Razor Script.
I have a Page with several children, and every child has a different document type. Like so:
Page:
Child (Doc type 1)
Child (Doc type 2)
Child (Doc type 3)
Child (Doc type 4)
What I am trying to do is, make a script that "lists all childs from current page"... Like the default template in Umbraco, named a like.
But... I need to create an if statement, that formats the content different according to the document type.
Like this:
If DocType1 - Do this
If DocType2 - Do this
If DocType3 - Do this
and
so on....
Hope this makes any sense, and that someone can help me out here? :)
Unexpected "if" keyword after "@" character. Once inside code, you do not need to prefix constructs like "if" with "@".
And when I remove the "@" I get this error:
Error occured
d:\web\inmedia.dk\www\MacroScripts\636050433622081432_listSectionTypes.cshtml(4): error CS0103: The name 'CurrentPage' does not exist in the current context
I am using Umbraco 6, if that has anything to say?
@inherits umbraco.MacroEngines.DynamicNodeContext
@* Ensure that the Current Page has children, where the property umbracoNaviHide is not True *@
@if (Model.Children.Where("Visible").Any())
{
<ul>
@* For each child page under the root node, where the property umbracoNaviHide is not True *@
@foreach (var childPage in Model.Children.Where("Visible"))
{
if(childPage.DocumentTypeAlias == "CallToAction"){
<li>Hello World!</li>
}
}
</ul>
}
But it seems like it doesn't work... I can save it without any errors, but it doesn't get the childPage with that documentTypeAlias.
Razor - Check for document type and create if statement
Hi I need some help on how to check for a specific document type in Razor Script.
I have a Page with several children, and every child has a different document type. Like so:
What I am trying to do is, make a script that "lists all childs from current page"... Like the default template in Umbraco, named a like. But... I need to create an if statement, that formats the content different according to the document type.
Like this:
and so on....
Hope this makes any sense, and that someone can help me out here? :)
No one that can help me out here?
Hi Mikkel,
Could you please try something like this and see if this solve what you are trying to do.
Hope this helps,
/Dennis
I get the following error:
And when I remove the "@" I get this error:
I am using Umbraco 6, if that has anything to say?
I tried using your example from above, like this:
But it seems like it doesn't work... I can save it without any errors, but it doesn't get the childPage with that documentTypeAlias.
Hi Mikkel,
Okay you are using the old dynamic node razor.
Could you then try to change:
To
Hope this helps,
/Dennis
Yes! that did the trick :)
Once again, Dennis Aaen comes to the rescue... Thank you very much your help, Dennis.... I can always count on you, it seems :)
BIG high five from me!
is working on a reply...