Copied to clipboard

Flag this post as spam?

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


  • mauricio lopez 12 posts 33 karma points
    Jul 02, 2010 @ 18:53
    mauricio lopez
    0

    check if umbraco:Item is empty

    Is there a way in the master template to verify if a umbraco:Item is empty and show an alternative content?

    I have this code in my master page:

    <div id="contenedor_slider">
    <asp:placeholder runat="server">
    <umbraco:Item runat="server" field="slidernivo" />
    </asp:placeholder>
    </div>

    The dynamic field "slidernivo" can be changed by the backend on an specific documenttype. The administrator can publish html images on it and a js component take them to create an slider. But sometimes some this space is nof filled for the admin, and the slider stays blank. So I would like to have a logic to show a default image.

    Please someone tell me what is the best approach.

  • bob baty-barr 1180 posts 1294 karma points MVP
    Jul 02, 2010 @ 19:48
    bob baty-barr
    0

    in the insert umbraco item dialog, you can have fallbacks if the content is empty...

    <umbraco:Item field="pageHeading"
     useIfEmpty="umbracoFile"
     textIfEmpty="You need to fill in one of the properties above"
     runat="server"></umbraco:Item>

    so in the example above, it the item is empty, we are displaying a diffrent item and if the second item is ALSO empty, we are displaying some text. You could make that a default image, etc.

    hope that helps

  • mauricio lopez 12 posts 33 karma points
    Jul 02, 2010 @ 20:19
    mauricio lopez
    0

    hey thanks a lot for the answer.

    But I still have problems. The useIfempty I can not use it, because I need a default value that can not be changed by the cms admin. The textIfempty looked promising

    but it did not like html tags, it just support text. Any other idea?

  • bob baty-barr 1180 posts 1294 karma points MVP
    Jul 02, 2010 @ 20:37
    bob baty-barr
    0

    you can use html by escaping the characters ie...

    &lt;img src=&quot;a p&quot;/&gt;

    you also might want to look into a couple of default value projects in the project section.

    http://our.umbraco.org/projects/developer-tools/standard-values-in-umbraco

    for example??? let me know if that helps.

  • mauricio lopez 12 posts 33 karma points
    Jul 02, 2010 @ 21:30
    mauricio lopez
    0
    you can use html by escaping the characters ie...

     

    Awesome, that made the trick.

    Thanks so much for sharing your knowledge

    This is really nice:

    Standard Values in Umbraco

     

    But I am using umbraco 4.5 so I have to be picky about projects until they are fully compatible.

    regards

     

     

Please Sign in or register to post replies

Write your reply to:

Draft