Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Feb 24, 2011 @ 13:20
    Ismail Mayat
    0

    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

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Feb 24, 2011 @ 13:23
    Ismail Mayat
    0

    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

  • Jonas Eriksson 930 posts 1825 karma points
    Feb 24, 2011 @ 13:23
    Jonas Eriksson
    1

    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 Eriksson 930 posts 1825 karma points
    Feb 24, 2011 @ 13:30
    Jonas Eriksson
    0
    @using umbraco.MacroEngines
    @{
    var node = new DynamicNode(1050);
    }
    <p>@node.Name</p>
  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Feb 24, 2011 @ 13:42
    Ismail Mayat
    0

    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

  • Jonas Eriksson 930 posts 1825 karma points
    Feb 24, 2011 @ 13:51
    Jonas Eriksson
    0

    Oh, very cool, I didnt try it yet, something like:

    @node.HcardAddress.item[0].name 
  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Feb 24, 2011 @ 13:54
    Sebastiaan Janssen
    0

    Try @node.hcardAddress.item[0].name?

    lol I keep posting at the same time as other people..

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Feb 24, 2011 @ 13:55
    Ismail Mayat
    1

    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

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Feb 24, 2011 @ 14:09
    Sebastiaan Janssen
    0

    Should just work like this I think:

    @node.hcardAddress.item.Where("name == {@0}", "somename")
  • Jonas Eriksson 930 posts 1825 karma points
    Feb 24, 2011 @ 15:53
    Jonas Eriksson
    0

    LOL "WOOOOOOHOOHOHOH wtf RAZOR KICKS ASS!!!!!" +1

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies