I've heard that razor scripting can be used in templates. I'm looking for some assistance to create the following functionality.
In one of my templates, I have a macro. I would like this macro to be called only under certain conditions. The condition is a True/False property in one of my Content nodes. If this can be made to work, it would go something like this (not real code):
<% if ContentNodeAlias/TruefalsePropertyAlias = 1 or (true) {
So basically, the script looks for a specific node and the value of a true/false property, and if checked, will render a macro, otherwise not. Is this possible?
No you can't do it like that as razor can't render macro's (easily).
Wouldn't it be much much easier to just put the logic IN the macro (where it belongs, more or less). So just say in your XSLT/Razor file "if this property is true then proceed with whatever, else just not return anything"?
If the macro was calling an XSLT file where I could put that conditional statement in, I would do that for sure. In my case, the macro is calling a usercontrol and I really dont have the ability or knowledge to make it conditional as described.
FYI: Inline Razor requires a macro control, and you can't nest macro's, this will throw an error (The 'Text' property of 'umbraco:Macro' does not allow child objects):
<umbraco:Macro Language="cshtml" runat="server">
@if (Model.MyProperty == False) { //This line is inline Razor, it needs to be inside an umbraco:Macro control
<umbraco:Macro Alias="siteFunction" runat="server"></umbraco:Macro>
}
</umbraco:Macro>
Ah in that case, in your macro, you can create macro parameters ("Developer"> "Macros"> "Your Macro"> go to the parameters tab). You can fill the macro parameter with this syntax:
That works great but not if you want to render a usercontrol. :-) It can only render Razor webpages (and possibly other pages?) but not usercontrols individually.
Asking for help for possible inline razor
I've heard that razor scripting can be used in templates. I'm looking for some assistance to create the following functionality.
In one of my templates, I have a macro. I would like this macro to be called only under certain conditions. The condition is a True/False property in one of my Content nodes. If this can be made to work, it would go something like this (not real code):
<% if ContentNodeAlias/TruefalsePropertyAlias = 1 or (true) {
<umbraco:Macro Alias="siteFunction" runat="server"></umbraco:Macro>
}
%>
So basically, the script looks for a specific node and the value of a true/false property, and if checked, will render a macro, otherwise not. Is this possible?
No you can't do it like that as razor can't render macro's (easily).
Wouldn't it be much much easier to just put the logic IN the macro (where it belongs, more or less). So just say in your XSLT/Razor file "if this property is true then proceed with whatever, else just not return anything"?
If the macro was calling an XSLT file where I could put that conditional statement in, I would do that for sure. In my case, the macro is calling a usercontrol and I really dont have the ability or knowledge to make it conditional as described.
FYI: Inline Razor requires a macro control, and you can't nest macro's, this will throw an error (The 'Text' property of 'umbraco:Macro' does not allow child objects):
Ah in that case, in your macro, you can create macro parameters ("Developer"> "Macros"> "Your Macro"> go to the parameters tab). You can fill the macro parameter with this syntax:
(more info on parameter syntax here)
Thank you, i'll have a look.
According to this blog you can use RenderPage but I haven't tested it myself
http://joeriks.wordpress.com/2011/03/11/better-structure-for-your-razor-scripts-with-renderpage-in-umbraco/
That works great but not if you want to render a usercontrol. :-) It can only render Razor webpages (and possibly other pages?) but not usercontrols individually.
Ahh yes, of course. I am so involved in soaking up the Razor implementations I have completely disregarded all other forms of macros! :-)
is working on a reply...