@Lau glad you figured it out :) For the Razor engine to understand you are typing Razor you need to prefix the if with @ so it knows it's code and say not just normal text or HTML.
I recommend reading over Scott Gu's post on an introduction to Razor so you can pick up the syntax
Newbie Question - if DocType
Hello,
So today, of all days. I look at a problem and say, hey! This is the right use for some sort of inline code, lets do it!
I want to display some text, but only on the homepage.
So many logic is
if doctype = Home
show this text!
How does one go about doing this in inline razor?
I got as far as...
<umbraco:Macro runat="server" language="razor">
@Model.NodeTypeAlias
{
<h2>@Model.contentHeader</h2>
}
</umbraco:Macro>
Try this:
Jeroen
Something along the lines of below should work. Razor is clever enough to work out when code stops and mark up begins.
Nope doesn't work!
But the code I posted does work, so the issue is with the @if?
Very confusing, for such a simple thing ;)
Does @Model.NodeTypeAlias work? should it be @Model.GetProperty('NodeTypeAlias').Value() ?
I've never used inline razor before. Only is .cshtml files. Maybe remove the @ so try this:
Jeroen
Okay so,
@Jay - yep it works!
@Jeroen - that didn't work, but the @Model.contentHeader bit did work...
So I thought, maybe if I add a @ infront of the if...
and it worked! (:
<umbraco:Macro runat="server" language="cshtml">
@if(Model.NodeTypeAlias=="Home")
{
<h2>@Model.contentHeader</h2>
}
</umbraco:Macro>
Isn't your answer the same as my post? Razor is a combination of HTML and C#. If you're using the @ it will enable you to use C# code. This blog might help :) http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx
Jeroen
@Lau glad you figured it out :)
For the Razor engine to understand you are typing Razor you need to prefix the if with @ so it knows it's code and say not just normal text or HTML.
I recommend reading over Scott Gu's post on an introduction to Razor so you can pick up the syntax
http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx
http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx
Cheers,
Warren
Thanks for all the help! Not quite sure what was going wrong, as Jeroen rightly said, you got it earlier! Thanks again, Laux
is working on a reply...