Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1287 posts 2744 karma points
    Apr 14, 2010 @ 21:12
    Amir Khan
    0

    Default media if none selected

    I have this bit of inline xslt in one of my templates that gets an item from the media library via a media picker datatype in one of my document types, is there a good way to define a default media item? I'd like it to be setup so that if the user doesn't specifically pick an image from the library before publishing the page, it will just use an image that I've defined.

    Thank you!

     

            <umbraco:Item runat="server" field="bannerImage" xslt="concat('&lt;img src=&quot;',umbraco.library:GetMedia({0}, true())/data[@alias='umbracoFile'], '&quot; /&gt;')" xsltDisableEscaping="true"/>

     

     

  • dandrayne 1138 posts 2262 karma points
    Apr 14, 2010 @ 21:24
    dandrayne
    0

    You could put this into simple xslt macro instead of the inline xslt (which imo gets very ugly very quickly)

    something like

    <xsl:choose>
    <xsl:when test="string($currentPage/data[@alias='bannerImage']) != ''">
    <img src="{umbraco.library:GetMedia($currentPage/data[@alias='bannerImage'], false() )/data[@alias='umbracoFile']}" />
    </xsl:when>
    <xsl:otherwise>
    <img src="/somewhere/somewhere.jpg" />
    </xsl:otherwise>
    </xsl:choose>

    also - do you need the true() to get children on your getmedia call?  If not, changing it to false will save apparently save quite a bit of db overhead.

    Dan

  • Paul Blair 466 posts 731 karma points
    Apr 14, 2010 @ 22:42
    Paul Blair
    0

    Amir,

    Another option you can use is to add the property bannerImmage to your root node (usually the homepage) and on your homepage select the default image. Then modify your inline xslt to be recursive:

    <umbraco:Item runat="server" field="bannerImage" 
    xslt="concat('&lt;img src=&quot;',umbraco.library:GetMedia({0},
    false())/data[@alias='umbracoFile'], '&quot; /&gt;')"
    xsltDisableEscaping="true" recursive="true" />

    Cheers

    Paul

  • Amir Khan 1287 posts 2744 karma points
    Apr 14, 2010 @ 23:08
    Amir Khan
    0

    Dan, Paul,


    Both excellent options. I understand some good reasoning for both, I went with the second one for the following reason.

    I have a main News & Events page, with several News / Events documents underneath them. I didn't want my client to have to manually select a new banner image everytime they created a new news item, the banner is there more for structure than for content specific to that news post. I also wanted them to be able to change the banner if they wanted to for a specific item.

    Thanks to both!

    Amir

Please Sign in or register to post replies

Write your reply to:

Draft