简体   繁体   English

使用Dreamweaver TBB中的TemplateBeginRepeat在不同的模板级别获取字段的值

[英]Getting the field's value at a different templating level using TemplateBeginRepeat in Dreamweaver TBB

I'm trying to write the Dreamweaver TBB and I am stuck at one point where I need to get the field value at a different template level. 我正在尝试编写Dreamweaver TBB,但我陷入了需要在另一模板级别获取字段值的问题。

Below is my XML where I need to get the inputType field present at formField level to the input Templating level. 下面是我的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>

To get the value in the same level we can use 为了获得相同水平的价值,我们可以使用

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

But my requirement is to get the inputValue at input templating level 但是我的要求是在输入模板级别获得inputValue

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

This code fails to return as there is no inputType present at input templating level. 此代码无法返回,因为在输入模板级别不存在inputType。 So i tried to use: 所以我尝试使用:

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

Here there are two issues when i use RenderComponentField the output looks like: 当我使用RenderComponentField时,这里有两个问题,输出看起来像:

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

its returning the value along with tcdl tags which I don't require. 它返回的值以及tcdl标签(我不需要)。

Secondly, instead of the index directly giving 0 , I need to use TemplateRepeatIndex , but its giving an error if i use @@RenderComponentField("formField[TemplateRepeatIndex].inputType",0)@@ 其次,我需要使用TemplateRepeatIndex ,而不是直接给出0的索引,但是如果我使用@@RenderComponentField("formField[TemplateRepeatIndex].inputType",0)@@则会出现错误。

So how can we achieve this if we want to get the field value at a different templating level. 因此,如果我们想获得不同模板级别的字段值,我们如何实现这一目标。

As you have discovered, it is not possible to access the "outer" TemplateRepeatIndex from the "inner" loop with the standard DWT functions. 如您所知,不可能使用标准DWT函数从“内部”循环访问“外部” TemplateRepeatIndex。

There are a few ways to solve this. 有几种解决方法。 The simplest is probably to write custom Dreamweaver callable functions that use the context variables to store and retrieve values. 最简单的方法可能是编写自定义Dreamweaver可调用函数 ,这些函数使用上下文变量来存储和检索值。

This approach is described well, with accompanying source code, at Get and Set Variables in DWTs | 在DWT中的“获取和设置变量”中 ,很好地描述了此方法及其随附的源代码 SDL Tridion Developer SDL Tridion开发人员

you have to use $ sign like below with TemplateRepeatIndex 您必须使用如下的$符号和TemplateRepeatIndex

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

Let me know if not work 让我知道是否行不通

Your question is a little confusing, but it seems like you have 2 issues 您的问题有点令人困惑,但似乎您有2个问题

  1. You have an extra <tcdl:ComponentField/> tag which you don't want 您有一个多余的<tcdl:ComponentField/>标记,您不需要
  2. You get an error when you use TemplateRepeatIndex 使用TemplateRepeatIndex时出现错误

If that is not correct, please consider modifying your question. 如果不正确,请考虑修改您的问题。

For issue number #1- can I assume you are seeing the <tcdl:ComponentField/> in Template Builder? 对于问题1,我可以假定您在模板生成器中看到<tcdl:ComponentField/>吗? Or are you seeing this in the final published page? 还是在最终发布的页面中看到了这一点? This tag is added to the output by the @@RenderComponentField@@ function to allow you to add SiteEdit of TridionUI markup to your output. 此标记通过@@RenderComponentField@@函数添加到输出中,以允许您将TridionUI标记的SiteEdit添加到输出中。 If should not end up in your published pages if you apply the 'Default Finish Actions' TBB at the end of your template. 如果您在模板的末尾应用“默认完成操作” TBB,则该结果不应出现在已发布的页面中。 The default templates contain code to clean up this tags after any SiteEdit/UI markup is applied. 默认模板包含应用任何SiteEdit / UI标记后清理此标记的代码。

For your second issue, take a look at these post ' How to handle nested repeating regions in Dreamweaver TBBs in SDL Tridion 2011 SP1 ' and ' http://www.tridiondeveloper.com/get-and-set-variables-in-dwts '. 对于第二个问题,请查看以下文章“ 如何在SDL Tridion 2011 SP1中的Dreamweaver TBB中处理嵌套的重复区域 ”和“ http://www.tridiondeveloper.com/get-and-set-variables-in-dwts ”。

Nested/embeded fields can be confusing using the default Tridion syntax for Dreamweaver, so you might consider using the great GetExtension from Nuno Linhares. 使用Dreamweaver的默认Tridion语法可能会使嵌套/嵌入字段令人困惑,因此您可以考虑使用Nuno Linhares提供的出色的GetExtension This will make your life much easier 这将使您的生活更加轻松

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM