4

我正在使用 SDL Tridion 2011 SP1。我正在为一个组件创建 Dreamweaver TBB。在我的组件中,一些字段是空的。但是在我的组件 TBB 中,我想检查该字段是否为空并且我不应该渲染它。如果字段不为空,那么我应该渲染并显示该值。我在检查嵌入字段中子字段的内容时遇到了问题。

在我的组件上有一个名为“EMBFIELD”的多值嵌入式模式字段。EMBFIELD 模式有一个名为“text”的文本字段。我想检查文本字段是否为空。如果它不为空,我必须遍历该字段以呈现值。

我必须仅通过“RenderComponentField”来呈现该字段。当我尝试渲染时,它显示该字段不存在的一些错误。

我认为这可以使用 If 块来完成。

 <!-- TemplateBeginIf cond="Component.Fields.EMBFIELD" --> 
     <!-- TemplateBeginRepeat name="Component.Fields.EMBFIELD" -->
           <!-- TemplateBeginIf cond="Component.Fields.EMBFIELD.text" --> 
                 <div>@@RenderComponentField("Component.Fields.EMBFIELD.text",TemplateRepeatIndex)@@</div>
            <!-- TemplateEndIf -->      
     <!-- TemplateEndRepeat -->
 <!-- TemplateEndIf -->

但它给出了错误

内部错误:上下文组件组件没有字段 Component.Fields.conditionalText.text

4

3 回答 3

6

您应该能够在尝试渲染之前使用 Dreamweaver 条件区域检查值。

例如:

<!-- TemplateBeginIf cond="Component.Fields.Field" -->
    @@Component.Fields.Field@@
<!-- TemplateEndIf -->
于 2012-03-14T09:00:42.787 回答
2

您可以使用StringLength(object parameter)函数,如果字段为空或无法确定参数的字符串长度,它将返回 0。所以总而言之,它应该是这样的:

<!-- TemplateBeginIf cond="StringLength(Component.Fields.Field) > 0" -->
 <b>Value is not empty<b>
 <p>@@Component.Fields.Field@@</p>
<!-- TemplateEndIf -->

这可能是您更新问题的答案:

<!-- TemplateBeginIf cond="Component.Fields.EMBFIELD.text" --> 
     <!-- TemplateBeginRepeat name="Component.Fields.EMBFIELD" -->
            @@RenderComponentField("EMBFIELD[${TemplateRepeatIndex}].text", 0)@@       
     <!-- TemplateEndRepeat -->
 <!-- TemplateEndIf -->
于 2012-03-14T09:02:31.117 回答
0

我们在访问嵌入式模式字段时遇到了同样的错误,并且在与构建器和调试进行了大量来回之后,dwt 了解到错误是关于没有在最后一个双 qoute 和 --> 之间放置空格TemplateBeginIf 语句。: DWT Mediator 输出的错误:

<!-- TemplateBeginIf cond="EMBEDFIELD.internalLink || EMBEDFIELD.externalLink || EMBEDFIELD.label"-->

以下不会出错:

<!-- TemplateBeginIf cond="EMBEDFIELD.internalLink || EMBEDFIELD.externalLink || EMBEDFIELD.label"<PUT_A_SPACE_HERE>-->

它可能是 RenderComponentField 语句周围的任何 TemplateBeginIf 出错。希望这可以帮助某人

于 2016-01-28T01:30:14.897 回答