Copied to clipboard

Flag this post as spam?

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


  • Dominic Kelly 114 posts 133 karma points
    Apr 24, 2014 @ 08:09
    Dominic Kelly
    0

    Hide umbraco:field if empty?

    Hi,

    I have a footer link that is set via a Content Picker on various multi-lingual homepages. This link needs to only display when a page has been selected in the admin. I've hacked it together by hiding it in jQuery like so:

    <li id="termsAndConditions"><a href="<umbraco:Item field="termsAndConditions" xslt="umbraco.library:NiceUrl({0})" runat="server" recursive="true" />" title="<umbraco:item field="#Terms&Conditions" runat="server" />"><umbraco:item field="#Terms&Conditions" runat="server" /></a></li>   
    
      <script type="text/javascript">
            $(document).ready(function () {
                var href = $("#termsAndConditions a").attr("href");
                if (href == "")
                {
                    $("#termsAndConditions").hide();
                }
            });
      </script>

    But ideally, I'd rather do something like:

    if(property("termsAndConditions") != null){
      <li><a href="#">The link</a></li>
    }

    What would the syntax be please?

     

     

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 24, 2014 @ 09:02
    Jan Skovgaard
    1

    Hi Dominic

    If you made an XSLT macro rather than using an inline XSLT call then you could easily control wether or not the link should be rendered. Then you also avoid using JavaScript for doing it.

    in xslt it could be something like

    Does this make sense?

    /Jan

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 24, 2014 @ 09:03
    Dennis Aaen
    0

    Hi Dominic,

    Did you see this documentation http://our.umbraco.org/wiki/how-tos/xslt-useful-tips-and-snippets/make-umbraco-fields-disappear-when-null,-using-in-line-xslt

    Another way could be to create a XSLT macro instead of inline XSLT, personally I think it more easier to create checks in a separate XSLT than Inline XSLT.

    Hope this can help you further.

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft