使用Dreamweaver TBB中的TemplateBeginRepeat将字段值设置为不同的模板级别

时间:2013-02-06 07:24:26

标签: tridion tridion-2011 dreamweaver-templates

我正在尝试编写Dreamweaver TBB并且我陷入了一个需要在不同模板级别获取字段值的位置。

下面是我的XML,我需要将formField级别的inputType字段输入到输入模板级别。

<formField>
    <divClassName>fieldClassName</divClassName>
    <label>Please enter your Name</label>
    <labelId>labelNameId</labelId>
    <inputType>text</inputType>
    <input>
        <inputName>sam</inputName>
        <inputId>ssss</inputId>
        <inputSize>40</inputSize>
        <inputLabel>xxx</inputLabel>
        <inputValue>zzz</inputValue>
    </input>
    <input>
        <inputName>gf</inputName>
        <inputId>g</inputId>
        <inputSize>fdg</inputSize>
        <inputLabel>sg</inputLabel>
        <inputValue>gsdfg</inputValue>
    </input>
    <param1>ssss</param1>
    <param2>ssss</param2>
</formField>

要获得相同级别的值,我们可以使用

<!-- TemplateBeginRepeat name="Component.Fields.formField" -->
    @@inputType@@
<!-- TemplateEndRepeat -->

但我的要求是将inputValue置于输入模板级别

<!-- TemplateBeginRepeat name="input" -->
    @@inputType@@
<!-- TemplateEndRepeat -->

此代码无法返回,因为输入模板级别没有inputType。所以我试着用:

<!-- TemplateBeginRepeat name="input" -->
    @@RenderComponentField("formField[0].inputType",0)@@
<!-- TemplateEndRepeat -->

这里有两个问题,当我使用RenderComponentField时输出如下:

<tcdl:ComponentField name="formField[0].inputType" index="0">
    text
</tcdl:ComponentField>

它返回值以及我不需要的tcdl标签。

其次,我需要使用TemplateRepeatIndex而不是直接给出0的索引,但如果我使用@@RenderComponentField("formField[TemplateRepeatIndex].inputType",0)@@

则会出错

那么,如果我们想要将字段值设置为不同的模板级别,我们怎样才能实现这一目标。

3 个答案:

答案 0 :(得分:2)

正如您所发现的那样,无法使用标准DWT函数从“内部”循环访问“外部”TemplateRepeatIndex。

有几种方法可以解决这个问题。最简单的可能是编写custom Dreamweaver callable functions,它使用上下文变量来存储和检索值。

此方法在Get and Set Variables in DWTs | SDL Tridion Developer

处附带了相应的源代码

答案 1 :(得分:1)

你必须使用下面的$ sign与TemplateRepeatIndex

@@ RenderComponentField( “formField [$ {TemplateRepeatIndex}]。的inputType”,0)@@

如果不行,请告诉我

答案 2 :(得分:1)

您的问题有点令人困惑,但似乎您有2个问题

  1. 您有一个额外的<tcdl:ComponentField/>标签,您不想要
  2. 使用TemplateRepeatIndex
  3. 时出错

    如果不正确,请考虑修改您的问题。

    对于问题编号#1-,我可以假设您在模板生成器中看到了<tcdl:ComponentField/>吗?或者您是否在最终发布的页面中看到了这一点?此标记由@@RenderComponentField@@函数添加到输出中,以允许您将TridionUI标记的SiteEdit添加到输出中。如果您在模板末尾应用“默认完成操作”TBB,则不应该在已发布的页面中结束。默认模板包含在应用任何SiteEdit / UI标记后清除此标记的代码。

    关于第二个问题,请查看这些帖子“How to handle nested repeating regions in Dreamweaver TBBs in SDL Tridion 2011 SP1”和“http://www.tridiondeveloper.com/get-and-set-variables-in-dwts”。

    嵌套/嵌入字段可能会使用Dreamweaver的默认Tridion语法造成混淆,因此您可以考虑使用Nuno Linhares中的精彩GetExtension。这将使您的生活更轻松