Copied to clipboard

Flag this post as spam?

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


  • Rachel Skuse 88 posts 118 karma points
    Feb 05, 2010 @ 10:37
    Rachel Skuse
    0

    Is it possible to hide an <li> if link not populated

    Hi,

    I'm currently using the following code to display some links...

    <ul class="downlinks">
        <li><a href='<umbraco:Item field="umbracoFile" nodeid="[#roomset]" runat="server"></umbraco:Item>' rel="lightbox">See this product in a roomset</a></li>
        <li><a href='<umbraco:Item field="umbracoFile" nodeid="[#fullSpecLink]" runat="server" target="_blank"></umbraco:Item>'>Download full specifications</a></li>
        <li><a href='<umbraco:Item field="umbracoFile" nodeid="[#userManual]" runat="server" target="_blank"></umbraco:Item>'>Download User Manual</a></li>
        <li><a href='<umbraco:Item field="umbracoFile" nodeid="[#addManual]" runat="server" target="_blank"></umbraco:Item>'>Additional Manual</a></li>
    </ul>

    It's possible that not all of these links will be populated, so my question is...is it possible to hide hide the list item if the link has nothing attached to it?

    Many thanks,

    Rachel

     

  • Tommy Poulsen 514 posts 708 karma points
    Feb 05, 2010 @ 10:51
    Tommy Poulsen
    0

    Hi Rachel,

    you have a number of attributes on the umbraco:item elements (link), but I'm not sure you will be able to remove the <li> elements.

    Alternatively you should create an xslt macro for either the full list or individual list elements taking the nodeid as argument, and the testing for empty links within the macro.

    >Tommy

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 05, 2010 @ 10:52
    Dirk De Grave
    1

    Me thinks you can change the syntax to:

    <umbraco:Item field="umbracoFile" nodeId="[#roomset]" insertTextBefore="&lt;li&gt;&lt;a href=&quot;" insertTextAfter="&quot; rel=&quot;lightbox&quot;&gt;See this product in a roomset&lt;/a&gt;&lt;/li&gt;" runat="server"></umbraco:Item>

    Haven't tried this, but worth a shot.... Otherwise, I'd suggest to move this piece of logic to an xslt file..

     

    Hope this helps.

    Regards,

    /Dirk

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Feb 05, 2010 @ 10:59
    Lee Kelleher
    1

    Hi Rachel,

    You can do this in XSLT, by wrapping IF conditions around each of the <li> tags:

    <xsl:if test="string($currentPage/data[@alias='userManual']) != ''">
        <xsl:variable name="file" select="umbraco.library:GetXmlNodeById($currentPage/data[@alias='userManual'])" />
        <xsl:if test="string($file/data[@alias='umbracoFile']) != ''">
            <li>
                <a href="{$file/data[@alias='umbracoFile']}">Download User Manual</a>
            </li>
        </xsl:if>
    </xsl:if>

    What's happening here? We're checking if your current page has a property value for 'userManual', then using that nodeId/value to get the node data - and then checking if the 'umbracoFile' has a value ... if so, then display the <li> tag.

    I haven't tested this XSLT ... you'll need to tweak it to suit your needs.

    Good luck, Lee.

  • Rachel Skuse 88 posts 118 karma points
    Feb 05, 2010 @ 11:27
    Rachel Skuse
    0

    Hi guys,

    Thanks for your quick responses.

    Dirk, I tried changing the syntax and it removed the link but it did so regardless of whether there is an attachment or not!

    So, I moved on to the xslt route, unfortunately my xslt knowledge is very limited at the moment so by best hope was to copy and paste the code that Lee provided -  this also removed the link regardless of whether there is an attachment or not!

    I appreciate you don't have time to write my code for me but if anyone has any tweaking suggestions on the above code it would be much appreciated.

    Thanks,

    Rachel

  • Tommy Poulsen 514 posts 708 karma points
    Feb 05, 2010 @ 13:24
    Tommy Poulsen
    1

    Hi Rachel, Lee's snippet assumes that you have the fields userManual,... as nodes on your current page. If these fields are media picker fields instead of content pickera, you would normally use GetMedia to fetch the image nodes. So you could try substituting GetXmlNodeById by GetMedia.

    Otherwise check if you go into the first IF.

    >Tommy

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Feb 05, 2010 @ 13:52
    Lee Kelleher
    0

    Hi Rachel,

    If you could provide some details about your content structure - as in which properties you use, etc. or copy-n-paste a sample from your /data/umbraco.config file (it's the XML cache of your site).  Then we should be able to point you in the right direction.

    You don't need to copy everything from umbraco.config - just a snippet of relevant content/nodes.

    Thanks, Lee.

  • Rachel Skuse 88 posts 118 karma points
    Feb 05, 2010 @ 18:04
    Rachel Skuse
    0

    Hi,

    Ok, I am using a media picker and so i substituted GetXmlNodeById for GetMedia and I know that this line returns the correct information (ie. link to my pdf download)

    <xsl:variable name="file" select="umbraco.library:GetMedia($currentPage/data [@alias='userManual'], 'false')/data [@alias = 'umbracoFile']"/>

     

    I know the first if statement works because whe I try the following:

    <xsl:if test="string($currentPage/data[@alias='userManual']) != ''">
        <li>
            <a href="#">Download User Manual</a>
            </li>
    </xsl:if>

    it displays the list item if userManual is not blank or doesn't display it if it is - this is exactly what I want but I need the link, if displayed, to link to userManual.

    For some reason, the second if doesn't appear to be working in the full code:

    <xsl:if test="string(current()/data[@alias='userManual']) != ''">
    <xsl:variable name="file" select="umbraco.library:GetMedia($currentPage/data [@alias='userManual'], 'false')/data [@alias = 'umbracoFile']"/>
    <xsl:if test="string($file/data[@alias='umbracoFile']) != ''">
    <li>
    <a href="{$file/data[@alias='umbracoFile']}">Download User Manual</a>
    </li>
    </xsl:if>
    </xsl:if>

    I hope this is a bit more helpful. I'm sorry but I'm not sure how to access the umbraco.config file??

    Many thanks,

    Rachel

     

     

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Feb 05, 2010 @ 18:19
    Lee Kelleher
    0

    Hi Rachel,

    Your 2nd code snippet is using "current()" - as in the current node - and your 3rd snippet is using $currentPage - which is the node of the current page. So there are different contexts.  Try replacing the "$currentPage" with "current()" - and see what happens.

    Cheers, Lee.

  • Rachel Skuse 88 posts 118 karma points
    Feb 05, 2010 @ 18:27
    Rachel Skuse
    0

    Sorry, I just realised that and was coming back to amend my post!

    My code now looks like this:

    <xsl:if test="string(current()/data[@alias='userManual']) != ''">
            <xsl:variable name="file" select="umbraco.library:GetMedia(current()/data [@alias='userManual'], 'false')/data [@alias = 'umbracoFile']"/>
            <xsl:if test="string($file/data[@alias='umbracoFile']) != ''">
                    <li>
                            <a href="{$file/data[@alias='umbracoFile']}">Download User Manual</a>
                    </li>
            </xsl:if>
    </xsl:if>

    but still no joy I'm afraid.

    Thanks, Rachel

     

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Feb 05, 2010 @ 18:31
    Lee Kelleher
    0

    Sorry Rachel, I re-read your code snippet ... I got it around the wrong way - swap the "current()" with "$currentPage" ... sorry about that - getting cross-eyed.

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Feb 05, 2010 @ 18:32
    Peter Dijksterhuis
    0

    I think you should use currentPage instead of current():

    <xsl:if test="string($currentpage/data[@alias='userManual']) != ''">
           
    <xsl:variable name="file" select="umbraco.library:GetMedia($currentpage/data [@alias='userManual'], 'false')/data [@alias = 'umbracoFile']"/>
           
    <xsl:if test="string($file/data[@alias='umbracoFile']) != ''">
                   
    <li>
                           
    <a href="{$file/data[@alias='umbracoFile']}">Download User Manual</a>
                   
    </li>
           
    </xsl:if>
    </xsl:if>

    Peter

  • Rachel Skuse 88 posts 118 karma points
    Feb 05, 2010 @ 18:38
    Rachel Skuse
    0
    <xsl:if test="string($currentPage/data[@alias='userManual']) != ''">
            <xsl:variable name="file" select="umbraco.library:GetMedia($currentPage/data [@alias='userManual'], 'false')/data [@alias = 'umbracoFile']"/>
            <xsl:if test="string($file/data[@alias='umbracoFile']) != ''">
                    <li>
                            <a href="{$file/data[@alias='umbracoFile']}">Download User Manual</a>
                    </li>
            </xsl:if>
    </xsl:if>

    Sorry Lee, still no joy :(

     

  • Rachel Skuse 88 posts 118 karma points
    Feb 05, 2010 @ 18:39
    Rachel Skuse
    0

    And thank you for your input Peter but as I said above, this still doesn't want to work!

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Feb 05, 2010 @ 18:41
    Peter Dijksterhuis
    1

    ah....now I see it. You allready have the umbracoFile in the variable. By calling it twice, it doesn't work.

    Try:

    <xsl:if test="string($currentPage/data[@alias='userManual']) != ''">
           
    <xsl:variable name="file" select="umbraco.library:GetMedia($currentPage/data [@alias='userManual'], 'false')/data [@alias = 'umbracoFile']"/>
           
    <xsl:if test="string($file) != ''">
                   
    <li>
                           
    <a href="{$file}">Download User Manual</a>
                   
    </li>
           
    </xsl:if>
    </xsl:if>

    Peter

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Feb 05, 2010 @ 18:47
    Lee Kelleher
    0

    Peter's way should work, but I'd do it the other way (leave the 'umbracoFile' select until later):

    <xsl:if test="string($currentPage/data[@alias='userManual']) != ''">
            <xsl:variable name="file" select="umbraco.library:GetMedia($currentPage/data[@alias='userManual'], 0)"/>
            <xsl:if test="string($file/data[@alias='umbracoFile']) != ''">
                    <li>
                            <a href="{$file/data[@alias='umbracoFile']}">Download User Manual</a>
                    </li>
            </xsl:if>
    </xsl:if>

    I wrote a blog post a while back about how to safely handle GetMedia nodes:

    http://blog.leekelleher.com/2009/11/30/how-to-use-umbraco-library-getmedia-in-xslt/

    Cheers, Lee.

  • Rachel Skuse 88 posts 118 karma points
    Feb 05, 2010 @ 19:03
    Rachel Skuse
    0

    You guys are awesome - both methods work just as I need them to. I'll be sure to read your blog Lee - thanks very much.

    One of the things I love about Umbraco is all the help & support. Hopefully I'll be able to offer my own someday!

    Thanks,

    Rachel

  • 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