开发者

How to add image titles to sc:image extension elements

开发者 https://www.devze.com 2023-01-25 19:13 出处:网络
I would like to be able to add a \"Title\" variable to images that are created using XSLT. Specifically, I am working with the file called \"Teasers.xslt\" which is part of the Sitecore6 Starter Kit.

I would like to be able to add a "Title" variable to images that are created using XSLT. Specifically, I am working with the file called "Teasers.xslt" which is part of the Sitecore6 Starter Kit. The text for each title would be the "Teaser Abstract" that is maintained in Sitecore Content Editor.

My understanding is that I can add a new variable to the "showteaser" xsl template, which can be made to query the Teaser Abstract as follows:

<xsl:variable name="title" select="sc:item(sc:fld('teaser abstract',.),.)" />

If this is correct, is it possible to add th开发者_如何学JAVAis new title variable as a property of the images? Below is the complete xsl template for "showteaser" (from Teasers.xslt) where I would like to insert the new title property:

<xsl:template name="showteaser">
    <xsl:param name="teaser_item" />
    <xsl:variable name="teaser" select="sc:item($teaser_item,.)" />
    <xsl:variable name="teaser_link" select="sc:item(sc:fld('teaser link',.),.)" />
    <sc:link field="teaser link" select="$teaser">
      <sc:image field="teaser image" select="$teaser" class="photo-border" w="200" h="100" as="1" bc="white" />
    </sc:link>
    <h2>
      <sc:link field="teaser link" select="$teaser">
        <sc:text field="teaser title" select="$teaser" />
      </sc:link>
    </h2>
    <p>
      <sc:memo field="teaser abstract" select="$teaser" />
    </p>
    <div class="read-more-link">
      <sc:link field="teaser link" select="$teaser">
        <sc:text field="text" select="$readmore" />
      </sc:link>
    </div>
  </xsl:template>

I have tried adding title as a variable to sc:link with no success. Is my assumption about how to go about this way off base? Thanks in advance, your help is greatly appreciated!


You probably solved your problem by now, but for the benefit of future users:

It seems that you will have to put the title attribute inside the -tag . You can do that using an attribute value template. That is, putting your expression inside curly backets:

<sc:image field="teaser image" select="$teaser" class="photo-border" w="200" h="100" as="1" bc="white" title="{sc:fld('teaser abstract',.)}" />


Could you use something like this:

 <sc:link field="teaser link" select="$teaser">
   <sc:image field="teaser image" select="$teaser" class="photo-border" w="200" h="100"    as="1" bc="white" >
     <xsl:attribute name="title">
        <xsl:value-of select="sc:fld('teaser abstract',.)" />
     </xsl:attribute>
   </sc:image>
</sc:link>

You should not this is only a suggest and I haven't tested this.

0

精彩评论

暂无评论...
验证码 换一张
取 消