This uses a text page field to populate the tag. Is it possible to populate the tag using the URL from a Media Picker property? On inserting the page field I can only get the image id number.
It would be neater doing this with a macro I reckon. Create a macro (here, I'm using XSLT) called 'metaImage' with a macro parameter with an alias of 'imageId' and type 'number'. Then put something like this in your macro to render the path of the image in a meta tag:
How to populate image meta tag
I am currently using umbraco:Items to populate meta tages in my template header.
This uses a text page field to populate the tag. Is it possible to populate the tag using the URL from a Media Picker property? On inserting the page field I can only get the image id number.
Hi Keir,
It would be neater doing this with a macro I reckon. Create a macro (here, I'm using XSLT) called 'metaImage' with a macro parameter with an alias of 'imageId' and type 'number'. Then put something like this in your macro to render the path of the image in a meta tag:
<xsl:variable name="domainName" select="concat('http://',umbraco.library:RequestServerVariables('HTTP_HOST'))"/>
<xsl:variable name="imageId" select="number(/macro/imageId)"/>
<xsl:template match="/">
<xsl:if test="$imageId > 0">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($imageId, 0)" />
<xsl:if test="$mediaNode/umbracoFile">
<meta property="og:image" content="{concat($domainName,$mediaNode/umbracoFile)}"/>
</xsl:if>
</xsl:if>
</xsl:template>
Then just call this macro in your template using advanced macro parameter syntax to pass the media id to your macro like this:
Much cleaner than trying to get it formatted in the template directly, it should render something like this in the browser:
is working on a reply...
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.