Copied to clipboard

Flag this post as spam?

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


  • Danne Borell 7 posts 27 karma points
    Sep 21, 2010 @ 10:10
    Danne Borell
    0

    Getting image from logotype property on homepage

    Hi, I have a webpage built like this in umbraco 4.5.2:

    Homepage

    Subpage

    Subsubpage

    Subsubpage

    Subpage

    Subsubpage

    Subsubpage

     

    On top of each page is the company logotype which acts as a link to the homepage, so it's pretty standard stuff.
    I want the editor to be able to select the logotype in on place, and then have it set on all pages dynamically.

    The best way I can figure out to do that would be to set the image as a property on the homepage and then use a xslt-macro to get the right image on each page.

    Problem is I only started using umbraco this week, and I have almost no experience with xslt before this. I'm having trouble even getting images with xslt, and then when I try to combine it with finding the ancestor page it just turns into a horrible mess.

    This is my latest attempt to get the image into a variable:

    <xsl:variable name="LogotypeVariable" select="umbraco.library:GetMedia($currentPage/ancestor-or-self::node [@template='startpage']/logotype, 0)"/>

     

    This is propably really simple once one knows how to do it, but I've been looking for an answer and found none.

    And if anyone would know of a good tutorial on image handling in umbraco in general I would really appreciate it if they'd let me know.

    /Danne Borell

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 21, 2010 @ 11:26
    Dirk De Grave
    1

    you can't use @template = 'startpage' as @template attribute is a number rather than text, so either use the number of the template, or even better, use the @level attribute as your home page (or 'startpage' document as you call it) will probably be the top level node in the content tree (well, the first node under 'Content')

    so, rewriting your xslt into:

    <xsl:variable name="LogotypeVariable" select="umbraco.library:GetMedia($currentPage/ancestor-or-self::node [@level=1]/logotype, 0)"/>

    should get you a reference to the media item, still will have to get the umbracoFile property of the LogotypeVariable.

    Combining both into a single statement should result in:

    <xsl:variable name="imageSource" select="umbraco.library:GetMedia($currentPage/ancestor-or-self::node [@level=1]/logotype, 0)/umbracoFile"/>

    and use that variable in an img tag

    <img src="{$imageSource}" />

     

    Hope this helps.

    Regards,

    /Dirk

  • Kim Andersen 1447 posts 2196 karma points MVP
    Sep 21, 2010 @ 12:00
    Kim Andersen
    1

    Danne,

    If you are using the new XML schema (when you are running v4.5.2 I think you do) you can for sure use Dirks great answer, but you just have to make a small change to it. You need to replace this:

    node

    with this:

    *[@isDoc]

    So the variable will look like this:

    <xsl:variable name="imageSource" select="umbraco.library:GetMedia($currentPage/ancestor-or-self::*[@isDoc][@level=1]/logotype, 0)/umbracoFile"/>

    /Kim A

  • Danne Borell 7 posts 27 karma points
    Sep 22, 2010 @ 10:39
    Danne Borell
    0

    Big thanks both of you, it worked like a charm :-)

    /Danne

  • Diogo Cunha 1 post 21 karma points
    Nov 05, 2010 @ 01:04
    Diogo Cunha
    0

    Great stuff! Thanks

Please Sign in or register to post replies

Write your reply to:

Draft