For inline Razor I think that less is better. If you need all kind of references and things get a bit more complicated than it's best to use a separate Razor Macro.
I too would trend towards your first example if possible, although you might be having trouble with one too many "@" symbols in there...Once you call @Html.Raw, anything you pass further into that no longer needs any other @ symbols, because your context has already switched to "code-context" instead of markup-context.
I also wonder if the "NodeById" method on your Model obj is problematic. I myself use @Library.NodeById usually for this, but if this works on Model as well then I just haven't seen that before.
Thank you for the speedy replies. My question was motivated by an issue i've been having with an itermitent Error Loading MacroEngine script (file: ) error. On the page the first 2 inline scripts run fine and 3 one breaks and all subsequent ones (2-3 more) on the page break all with the same error. Confusing because most of the time the page loads fine. I suspected is was a parsing issue or a syntax problem. I'm thinking now that the extra @ might be the culprit that throws off the parser. Since I've done that 3 or more times on the page.
I'm assuming that the @Model.NodeById is ok based on this resource page:
Syntax for Inline Razor Macros
I'm running 4.7.2 and I'm having some parse issues with some of my inline Razor code. I can't seem to find a definitive answer about proper syntax.
Which of the following is correct?
<div class="bannermsg">
<umbraco:Macro runat="server" language="cshtml">
<a href="@Model.NodeById(Model.banner1Link).Url">@Html.Raw(@Model.banner1Message)</a>
</umbraco:Macro>
</div>
Or this?
<div class="bannermsg">
<umbraco:Macro runat="server" language="cshtml">
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
<a href="@Model.NodeById(Model.banner1Link).Url">@Html.Raw(@Model.banner1Message)</a>
}
</umbraco:Macro>
</div>
Is there a good reference that cleary states what the best practice is for inline Razor macros?
For inline Razor I think that less is better. If you need all kind of references and things get a bit more complicated than it's best to use a separate Razor Macro.
Jeroen
I too would trend towards your first example if possible, although you might be having trouble with one too many "@" symbols in there...Once you call @Html.Raw, anything you pass further into that no longer needs any other @ symbols, because your context has already switched to "code-context" instead of markup-context.
I also wonder if the "NodeById" method on your Model obj is problematic. I myself use @Library.NodeById usually for this, but if this works on Model as well then I just haven't seen that before.
Try changing your first example to this instead?
<div class="bannermsg">
<umbraco:Macro runat="server" language="cshtml">
<a href="@Library.NodeById(Model.banner1Link).Url">@Html.Raw(Model.banner1Message)</a>
</umbraco:Macro>
</div>
Good luck!
Thank you for the speedy replies. My question was motivated by an issue i've been having with an itermitent Error Loading MacroEngine script (file: ) error. On the page the first 2 inline scripts run fine and 3 one breaks and all subsequent ones (2-3 more) on the page break all with the same error. Confusing because most of the time the page loads fine. I suspected is was a parsing issue or a syntax problem. I'm thinking now that the extra @ might be the culprit that throws off the parser. Since I've done that 3 or more times on the page.
I'm assuming that the @Model.NodeById is ok based on this resource page:
http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/dynamicnode-(and-model)-members-and-properties
But would welcome clarification on that. With the various libraries and kinds of code mixed on the page it can get a bit confusing.
I've removed the extra @s. We'll see how the page behaves and if that's it i'll mark this ias solved.
is working on a reply...