Sitecore XSLHelper.fld 方法未按预期工作 [英] Sitecore XSLHelper.fld Method not working as expected

查看:37
本文介绍了Sitecore XSLHelper.fld 方法未按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 XSLHelper.fld 方法时遇到了一些麻烦.我有一个非常简单的 XSLT 文件,我正在尝试访问我的 Sitecore 图像项中的子值.

I'm having some troubles with XSLHelper.fld method. I have a very simple XSLT file that I am trying to access sub-values that are inside my Sitecore image item.

代码示例:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:sc="http://www.sitecore.net/sc" 
  xmlns:dot="http://www.sitecore.net/dot"
  exclude-result-prefixes="dot sc">

<!-- output directives -->
<xsl:output method="html" indent="no" encoding="UTF-8" />

<!-- parameters -->
<xsl:param name="lang" select="'en'"/>
<xsl:param name="id" select="''"/>
<xsl:param name="sc_item"/>
<xsl:param name="sc_currentitem"/>

<!-- variables -->
<!-- Uncomment one of the following lines if you need a "home" variable in you code -->
<!--<xsl:variable name="home" select="sc:item('/sitecore/content/home',.)" />-->
<!--<xsl:variable name="home" select="/*/item[@key='content']/item[@key='home']" />-->
<!--<xsl:variable name="home" select="$sc_currentitem/ancestor-or-self::item[@template='site root']" />-->

<!-- entry point -->
<xsl:template match="*">
  <xsl:apply-templates select="$sc_item" mode="main"/>
</xsl:template>

<!--==============================================================-->
<!-- main                                                         -->
<!--==============================================================-->  
<xsl:template match="*" mode="main">

  TEST BACKGROUND IMAGE
  <br/>
  ALT: <br/>
  <xsl:value-of select="sc:fld('background',.,'alt')"/>
  <br/>
  SRC: <br/>
  <xsl:value-of select="sc:fld('background',.,'src')"/>
  <br/>
  Field SRC: <br/>
  <xsl:value-of select="sc:field('background',.,'src')"/>


</xsl:template>

</xsl:stylesheet>

当我测试下面的代码时,结果很奇怪,从下面的截图可以看出:

When I test the following code, the results are strange as can be seen from the following screenshot:

可以清楚地看到,alt 字段有值,src 字段为空.所以我绝对可以访问我的 Sitecore 图片项目,但无法访问 src 字段.....

You can clearly see that the alt field has a value and the src field is empty. So I definitely have access to my Sitecore image item but cannot get access to the src field.....

谁能解释一下为什么 src 字段为空?

Can anyone shed some light on why the src field is empty?

问候,

漫画编码器

推荐答案

正如我在您的另一个问题中所述,图像字段的原始值中不再有 src 属性.如果您修改图像字段属性中的替代文本,则 alt 属性存在,否则它将回退到媒体库中图像项上的替代文本.

As I stated on your other question, there is no longer a src attribute in the raw value of image fields. The alt attribute exists if you modify the Alternate Text in the properties of the image field or it will fall back to the alt text on the image item in the media library.

sc:field 方法使用字段渲染器输出完整的 标签.该方法的第三个参数应该用于附加参数,如宽度和高度或附加属性.它应该格式化为查询字符串(例如 width=150&height=100).它可能只是忽略了您传递的 src 值,因为它无效.

The sc:field method uses a field renderer to output a full <img> tag. The third parameter to that method is supposed to be for additional parameters like width and height or additional attributes. It should be formatted as a query string (e.g. width=150&height=100). It is probably just ignoring the src value that you are passing because it isn't valid.

这篇关于Sitecore XSLHelper.fld 方法未按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆