Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Guys,
I am using 4.7 and trying the following in my Umbraco template
<umbraco:macro runat="server" language="razor"> dynamic node = new DynamicNode(1064); </umbraco:macro>
getting the home node then i will get property called hcardAddress this is of type embed content i will then look to write those items out .
At moment just running that i get literal string written out in my template its not running the code no doubt i am missing something very obvious?
Regards
Ismail
ok bit of progress forgot the @{} wrapper which is core razor DOH!! Ok so now i get missing
The type or namespace name 'DynamicNode' could not be found (are you missing a using directive or an assembly reference?)
so where does DynamicNode live?
Hi Ismail, to make the parser sure you're adding code and not text you have to enclose the code in @{ }
Something like:
<umbraco:macro runat="server" language="razor"> @{ dynamic node = new DynamicNode(1064); } <p>@node.Name</p></umbraco:macro>
@using umbraco.MacroEngines@{ var node = new DynamicNode(1050); } <p>@node.Name</p>
Jonas,
According to http://our.umbraco.org/forum/developers/razor/17682-DynamicXml-not-working you can do some crazy xml stuff my property called hcardAddress of type embed content which stores xml of format:
<hcardAddress> <data> <item id="1"> <name propertyid="1">fn org</name> <value propertyid="2">Cogworks Ltd</value> </item> <item id="2"> <name propertyid="1">street-address</name> <value propertyid="2">11-15 Betterton Street</value> </item> <item id="3"> <name propertyid="1">locality</name> <value propertyid="2">London</value> </item> <item id="4"> <name propertyid="1">postal-code</name> <value propertyid="2">WC2H 9BP</value> </item> <item id="5"> <name propertyid="1">email</name> <value propertyid="2">[email protected]</value> </item> <item id="6"> <name propertyid="1">tel</name> <value propertyid="2">020 7470 8882</value> </item> </data> </hcardAddress>
should allow me to do something like:
<umbraco:macro runat="server" language="razor"> @using umbraco.MacroEngines @{ dynamic node = new DynamicNode(1064); } @node.hcardAddress.data.item[0].name </umbraco:macro>
however when i try this i get Error loading Razor Script
'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'data'
any ideas?
Many thanks
Oh, very cool, I didnt try it yet, something like:
@node.HcardAddress.item[0].name
Try @node.hcardAddress.item[0].name?
lol I keep posting at the same time as other people..
WOOOOOOHOOHOHOH wtf RAZOR KICKS ASS!!!!!
so i take it my default it will capitalise your alias. Also how would you do where name =fn org would you loop through all of them with if statement or can you use linq?
Should just work like this I think:
@node.hcardAddress.item.Where("name == {@0}", "somename")
LOL "WOOOOOOHOOHOHOH wtf RAZOR KICKS ASS!!!!!" +1
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Razor newbie
Guys,
I am using 4.7 and trying the following in my Umbraco template
<umbraco:macro runat="server" language="razor">
dynamic node = new DynamicNode(1064);
</umbraco:macro>
getting the home node then i will get property called hcardAddress this is of type embed content i will then look to write those items out .
At moment just running that i get literal string written out in my template its not running the code no doubt i am missing something very obvious?
Regards
Ismail
ok bit of progress forgot the @{} wrapper which is core razor DOH!! Ok so now i get missing
The type or namespace name 'DynamicNode' could not be found (are you missing a using directive or an assembly reference?)
so where does DynamicNode live?
Regards
Ismail
Hi Ismail, to make the parser sure you're adding code and not text you have to enclose the code in @{ }
Something like:
<umbraco:macro runat="server" language="razor">
@{
dynamic node = new DynamicNode(1064);
}
<p>@node.Name</p>
</umbraco:macro>
Jonas,
According to http://our.umbraco.org/forum/developers/razor/17682-DynamicXml-not-working you can do some crazy xml stuff my property called hcardAddress of type embed content which stores xml of format:
<hcardAddress> <data> <item id="1"> <name propertyid="1">fn org</name> <value propertyid="2">Cogworks Ltd</value> </item> <item id="2"> <name propertyid="1">street-address</name> <value propertyid="2">11-15 Betterton Street</value> </item> <item id="3"> <name propertyid="1">locality</name> <value propertyid="2">London</value> </item> <item id="4"> <name propertyid="1">postal-code</name> <value propertyid="2">WC2H 9BP</value> </item> <item id="5"> <name propertyid="1">email</name> <value propertyid="2">[email protected]</value> </item> <item id="6"> <name propertyid="1">tel</name> <value propertyid="2">020 7470 8882</value> </item> </data> </hcardAddress>
should allow me to do something like:
<umbraco:macro runat="server" language="razor">
@using umbraco.MacroEngines
@{
dynamic node = new DynamicNode(1064);
}
@node.hcardAddress.data.item[0].name
</umbraco:macro>
however when i try this i get Error loading Razor Script
'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'data'
any ideas?
Many thanks
Ismail
Oh, very cool, I didnt try it yet, something like:
Try @node.hcardAddress.item[0].name?
lol I keep posting at the same time as other people..
WOOOOOOHOOHOHOH wtf RAZOR KICKS ASS!!!!!
so i take it my default it will capitalise your alias. Also how would you do where name =fn org would you loop through all of them with if statement or can you use linq?
Regards
Ismail
Should just work like this I think:
LOL "WOOOOOOHOOHOHOH wtf RAZOR KICKS ASS!!!!!" +1
is working on a reply...