Copied to clipboard

Flag this post as spam?

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


  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Jan 13, 2012 @ 15:06
    Bjarne Fyrstenborg
    0

    Add meta from xslt

    Hi..

    Is is possible to add meta information dynamically from an xslt-file..

    I have a xslt file for the product page: http://sub.ak-security.dk/da/shop/brandmateriel/ildslukker.aspx with a Facebook Like button.. but Facebook not always detect this right image to use.. so I think I need to add something like this in the head section, the specify the image:

    <meta property="og:image" content="tag value"/> 

    according to this: http://developers.facebook.com/docs/reference/plugins/like/

    I have variables for product an variants, so I can easily get the right image..

    Bjarne

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 13, 2012 @ 17:09
    Chriztian Steinmeier
    2

    Hi Bjarne,

    Treat this as any other element you need to output - grab the data from Umbraco and output it somehow.

    Assuming you're in XSLT here, you'd have a macro in the head section of the template - since you're outputting an image url, you could just modify a macro that outputs an image, and output this meta element instead.

    Where is your image located - is it an Upload field or a Media Picker somewhere?

    /Chriztian

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Jan 13, 2012 @ 18:00
    Bjarne Fyrstenborg
    0

    Hi Chriztian..

    Yes, I was thinking I could do it that way.. just wondering if it was possible to do it direct from the product xslt file..

    I'm using DAMP, so I can add multiples images for each product.. either on the product itself or the variants..
    I already had a variable to use the product image of the product.. if it hasn't one it uses the first variant image.. otherwise it just display an empty image graphic using ImageGen altImage parameter.. :

    <xsl:variable name="category" select="./ancestor-or-self::* [name() = 'ProductCategory'][1]"/>
    <xsl:variable name="product" select="./ancestor-or-self::Product [last()]"/>
    <xsl:variable name="variants" select="$product/descendant-or-self::Product [not(child::Product)]"/>
    <xsl:variable name="variant" select="./descendant-or-self::Product [not(child::Product)][1]"/>
    <xsl:variable name="nodeLink" select="umbraco.library:NiceUrl($product/@id)"/>

    <ul>
            <xsl:for-each select="./productImage">
              <xsl:variable name="mediaImageXml">
                <xsl:choose>
                <xsl:when test="$product/productImage != ''">
                  <xsl:copy-of select="$product/productImage/DAMP/mediaItem[1]/Image"/>
                </xsl:when>
                <xsl:when test="$variant/productImage != ''">
                  <xsl:copy-of select="$variant/productImage/DAMP/mediaItem[1]/Image"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:copy-of select="./productImage/DAMP/mediaItem[1]/Image"/>
                </xsl:otherwise>
                </xsl:choose>
              </xsl:variable>
            
              <xsl:variable name="mediaImage" select="msxml:node-set($mediaImageXml)/*"/>
              <li>
                <img src="{concat('/ImageGen.ashx?altImage=/gfx/no_image.gif&amp;Image=',$mediaImage/umbracoFile,'&amp;Width=',$imgWidth)}" id="productImage" alt=""  />
    </li>
    </xsl:for-each>
    </ul>

    Both the product and variants (children) is using the Product doc type and have the same properties..

    Bjarne 

     

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Jan 14, 2012 @ 13:37
    Bjarne Fyrstenborg
    0

    Hi..

    I created a new xslt file and used this code.

    <xsl:variable name="siteName" select="'AK-Security'"/>
    <xsl:variable name="url" select="concat('http://',umbraco.library:RequestServerVariables('HTTP_HOST'))" />
    <!--<xsl:variable name="category" select="./ancestor-or-self::* [name() = 'ProductCategory'][1]"/>-->
    <xsl:variable name="product" select="$currentPage/ancestor-or-self::Product [last()]"/>
    <!--<xsl:variable name="variants" select="$product/descendant-or-self::Product [not(child::Product)]"/>-->
    <xsl:variable name="variant" select="$product/descendant-or-self::Product [not(child::Product)][1]"/>
    <xsl:variable name="nodeLink" select="umbraco.library:NiceUrl($currentPage/@id)"/>
      
    <xsl:variable name="mediaImageXml">
      <xsl:choose>
        <xsl:when test="$product/productImage != ''">
          <xsl:copy-of select="$product/productImage/DAMP/mediaItem[1]/Image"/>
        </xsl:when>
        <xsl:when test="$variant/productImage != ''">
          <xsl:copy-of select="$variant/productImage/DAMP/mediaItem[1]/Image"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:copy-of select="$url"/><xsl:value-of select="'/gfx/no_image.jpg'"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="mediaImage" select="msxml:node-set($mediaImageXml)/*"/>

    <xsl:if test="$currentPage/ancestor-or-self::Product">
    <meta property="og:title" content="{$product/productName}" />
    <meta property="og:description" content="{umbraco.library:StripHtml($product/productDescription)}"/>
    <meta property="og:type" content="website" />
    <meta property="og:url" content="{$url}{$nodeLink}" />
    <meta property="og:image" content="{$url}{$mediaImage/umbracoFile}" />
    <meta property="og:site_name" content="{$siteName}" />
    <meta property="fb:admins" content="546598307" />
    </xsl:if>

    which works as expected.. a small thing is, when there isn't an image on the product og variant, I want to use an empty image graphic, but with the code above I only get the first part of the url with the domain.. I need to get /gfx/no_image.gif too.. on the productimages it's working..

    I noticed that I could use this tool http://developers.facebook.com/tools/debug to check if the tags and content is correct..
    It is also required to use: title, type, image, url, site_name and an id with fb:admins or fb:app_id to get it working.. 

    Bjarne

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Jan 15, 2012 @ 15:16
    Bjarne Fyrstenborg
    100

    I'm not sure I can have the url to the static image inside the mediaImageXml.. when I then use node-set on that variable..

    But I solved it this way:

    <xsl:variable name="siteName" select="'AK-Security'"/>
    <xsl:variable name="url" select="concat('http://',umbraco.library:RequestServerVariables('HTTP_HOST'))" />
    <!--<xsl:variable name="category" select="./ancestor-or-self::* [name() = 'ProductCategory'][1]"/>-->
    <xsl:variable name="product" select="$currentPage/ancestor-or-self::Product [last()]"/>
    <!--<xsl:variable name="variants" select="$product/descendant-or-self::Product [not(child::Product)]"/>-->
    <xsl:variable name="variant" select="$product/descendant-or-self::Product [not(child::Product)][1]"/>
    <xsl:variable name="nodeLink" select="umbraco.library:NiceUrl($currentPage/@id)"/>
      
    <xsl:variable name="mediaImageXml">
      <xsl:choose>
        <xsl:when test="$product/productImage != ''">
          <xsl:copy-of select="$product/productImage/DAMP/mediaItem[1]/Image/umbracoFile"/>
        </xsl:when>
        <xsl:when test="$variant/productImage != ''">
          <xsl:copy-of select="$variant/productImage/DAMP/mediaItem[1]/Image/umbracoFile"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:copy-of select="$url"/><xsl:value-of select="'/gfx/no_image.gif'"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="mediaImage" select="msxml:node-set($mediaImageXml)/*"/>

    <xsl:if test="$currentPage/ancestor-or-self::Product">
    <meta property="og:title" content="{$product/productName}" />
    <meta property="og:description" content="{umbraco.library:StripHtml($product/productDescription)}"/>
    <meta property="og:type" content="website" />
    <meta property="og:url" content="{$url}{$nodeLink}" />

    <xsl:choose>
    <xsl:when test="$product/productImage != '' or $variant/productImage != ''">
      <meta property="og:image" content="{$url}{msxml:node-set($mediaImage)}" />
    </xsl:when>
    <xsl:otherwise>
      <meta property="og:image" content="{$url}/gfx/no_image.gif" />
    </xsl:otherwise>
    </xsl:choose>

    <meta property="og:site_name" content="{$siteName}" />
    <meta property="fb:admins" content="546598307" />
    </xsl:if>

    Bjarne

Please Sign in or register to post replies

Write your reply to:

Draft