Copied to clipboard

Flag this post as spam?

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


  • Peter Duncanson 430 posts 1360 karma points c-trib
    Nov 06, 2009 @ 16:47
    Peter Duncanson
    0

    Can I use asp.net angle bracket notation to access umbraco values?

    I was trying to build up my meta keyword element in my code and want to include any custom keywords per page and then bolt on some standard ones on the end. I did not want to use a macro as its a bit over kill (and you end up with lots of them) and its a one shot wonder on this site, it won't get used again.

    Then I tried using something like this:

    <umbraco:Item field="metaKeywords" textIfEmpty="" insertTextBefore="&lt;meta name=&quot;keywords&quot; content=&quot;" insertTextAfter="my default keywords here&quot; /&gt;" case="lower" htmlEncode="true" stripParagraph="true" runat="server"></umbraco:Item>

    But I simply find this really counter intuitive and I simply HATE writing element code encoded inside another element, its just all wrong.

    So how best to do it. In ASP.net or Class ASP I'd do something like this:

    <meta name="keyword" content="<%= page.metaKeywords %> my default keywords here" />

    Is this doable? If so how to do you get to the umbraco page object and is there any docs on whats available.

    More importantly is this the "umbraco way"? Am I missing a handy shortcut that I can't find in the docs?

    Cheers

    Pete

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 06, 2009 @ 17:30
    Dirk De Grave
    0

    Pete,

    Can't you just use

    <meta name="keyword" content="<umbraco:Item runat='server' field='metaKeywords'></umbraco:Item> my default items" />

     

    Hope this helps.

    Regards,

    /Dirk

  • Petr Snobelt 923 posts 1535 karma points
    Nov 06, 2009 @ 18:23
    Petr Snobelt
    1
    <umbraco:Item field="pageName" insertTextBefore="&lt;meta
    name=&quot;keywords&quot; content=&quot;"
    insertTextAfter="&quot; /&gt;"
    runat="server"></umbraco:Item>
    

    @Dirk try look at http://www.richardsoeteman.net/CommentView,guid,90e0ca4a-0e98-4962-9d86-5381d57e6ae7.aspx#commentstart

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Nov 06, 2009 @ 19:03
    Peter Duncanson
    0

    Dirk I tried your solution but it kept throwing an error, then after reading Petr link I see why, you had single quotes in your umbraco tag I was using doubles! Tried it again and it worked.

    So many solutions, still none of them feel "funky" though...

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Nov 07, 2009 @ 07:55
    Casey Neehouse
    1

    Use umbraco.library...

    <%=umbraco.library.GetItem('pageName')%>

     

  • Petr Snobelt 923 posts 1535 karma points
    Nov 07, 2009 @ 08:27
    Petr Snobelt
    0

    @Casey: Great idea, I'm thinking about nodeFactory, but getitem is right way :-)

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Nov 07, 2009 @ 15:44
    Casey Neehouse
    3

    @Petr,

    nodeFactory would be a great option as well.

    I would like to see someone come up with a chainable class, or a series of overloads for something like GetItem that does all the features that the <umbraco:item../> tag accomplishes.

    currentPage.getProperty("field1").recursive();
    currentPage.getProperty('field1").useIfEmpty("field2").textIfEmpty("My text")...
    umbraco.library.GetItem(string field, string useIfEmpty, string textIfEmpty, bool recursive)

    The latter probably being the most fool-proof.

     

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Nov 09, 2009 @ 14:31
    Peter Duncanson
    0

    Thats more like it Casey, thats exactly the kind of thing I was after! Is it good practise though?

Please Sign in or register to post replies

Write your reply to:

Draft