Copied to clipboard

Flag this post as spam?

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


  • Barry 99 posts 187 karma points
    Aug 28, 2009 @ 10:03
    Barry
    0

    Whats the correct way to reference a field value in meta data

    I am using this..

     <meta name="description" content="<umbraco:Item field='metaDescription' recursive='true' runat='server'></umbraco:Item>" />

    However, this is bad - just try and export the raw data out and import it in using any SQL tool - it really doesnt like it . Is there a better way to do this? I guess the alternative is to use a macro to ouput the meta data? but not sure how that would look.

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 28, 2009 @ 10:46
    Peter Dijksterhuis
    0

    I'm not exactly sure what you're after here?

    If you put this in your template, doesn't the meta-data display correctly in the source of your webpage?

    I don't see the link with any SQL-tool here really, can you explain what you mean with that or what you are trying to achieve?

  • Richard Soeteman 4045 posts 12893 karma points MVP 2x
    Aug 28, 2009 @ 11:18
    Richard Soeteman
    0

    Hi Barry,

    I think you have issues with the metaDescription field in HTML, that it doesn't output the content? I've written a blogpost about that a while back. Also check the comment from Petr which works also very well.

    Cheers,

    Richard

  • Barry 99 posts 187 karma points
    Aug 28, 2009 @ 11:21
    Barry
    0

    Sorry, I will explain..

    I used Visual Studio to perform a data compare , this scripted out the data from the umbraco db . However, this script will not run on any other sql server database due to the mixed single quote/double-quote text - caused by the umbraco macro being within the meta tag. If you use an umbraco macro on a template outside of the meta tags it uses double quotes for the properties. I guess ideally, I'd like to do this:

     <meta name="description" content="<umbraco:Item field="metaDescription" recursive="true" runat="server"></umbraco:Item>" />

    Or

    <meta name="description" content="[#metaDescription]" />

    (# replace with umbraco field).

    The safe alternative at the moment is to use a macro to set the whole metadata , the macro outputs the tags. I guess this is the best way?

  • Soeren Sprogoe 575 posts 259 karma points
    Aug 28, 2009 @ 12:06
    Soeren Sprogoe
    1

    I usually use a macro for the meta data, that way I can also build in some "intelligence" if the user forgets to write something in the meta description field.

    Here's an example of my macro, that checks if the user has entered a description text. If not, it just takes the first 160 characters of the bodyText.

    <xsl:variable name="description" select="umbraco.library:Replace(umbraco.library:Replace(umbraco.library:StripHtml($currentPage/data [@alias = 'metaDescription']),'&#xD;',''),'&#xA;','')" />
    <xsl:variable name="bodyText" select="umbraco.library:Replace(umbraco.library:Replace(umbraco.library:StripHtml($currentPage/data [@alias = 'bodyText']),'&#xD;',''),'&#xA;','')" />

    <xsl:template match="/">
    <meta>
    <xsl:attribute name="name">description</xsl:attribute>
    <xsl:choose>
    <xsl:when test="$description=''" >
    <xsl:attribute name="content"><xsl:value-of select="umbraco.library:TruncateString($bodyText, '160', '')"/></xsl:attribute>
    </xsl:when>
    <xsl:otherwise>
    <xsl:attribute name="content"><xsl:value-of select="$description" disable-output-escaping="yes"/></xsl:attribute>
    </xsl:otherwise>
    </xsl:choose>
    </meta>
    </xsl:template>
  • Tom Madden 253 posts 455 karma points MVP 4x c-trib
    Aug 28, 2009 @ 17:51
    Tom Madden
    2

    Barry,

     

    another option is to use the insertTextBefore and insertTextAfter properties to build the surround meta tags. i use this all the time, it's simpler and quicker than creating a macro, but obviously less powerful.

     

    <umbraco:Item field="metaDescription" insertTextBefore="&lt;meta name=&quot;description&quot; content=&quot;" insertTextAfter="&quot; /&gt;" recursive="true" runat="server"/>
    <umbraco:Item field="metaKeywords" insertTextBefore="&lt;meta name=&quot;keywords&quot; content=&quot;" insertTextAfter="&quot;/&gt;" recursive="true" runat="server"></umbraco:Item>
    Tom

Please Sign in or register to post replies

Write your reply to:

Draft