Dreamweaver模板中的循环和TemplateRepeatIndex

kri*_*r k 6 dreamweaver dreamweaver-templates dwt tridion

我在访问变量方面遇到了一些麻烦,在本例中为Setvariable.当我进入循环内部时,变量不存在.任何人都对此有任何见解.感谢您的帮助

下面是模板中的代码部分.当你有机会时,请你帮忙吗?谢谢.

<!-- TemplateBeginRepeat name="Component.Fields.section" -->
@@SetVariable("columnSectionIndex", "${TemplateRepeatIndex}")@@
Inline Value @@GetVariable("columnSectionIndex")@@       Variable value can be accessed
    <!-- TemplateBeginRepeat name ="Field.links" -->
      Inside Loop Value @@GetVariable("columnSectionIndex")@@  //Not getting declared           variable //value here. Says variable doesn’t exist in ContextVariables.
       <!-- TemplateBeginRepeat name ="Field.linkimages" -->
       <!-- TemplateEndRepeat -->
    <!-- TemplateEndRepeat -->
<!-- TemplateEndRepeat -->
Run Code Online (Sandbox Code Playgroud)

产量

Variable Added Successfully
Inline Value 0 
Inside Loop Value Variable doesn't exist 
Run Code Online (Sandbox Code Playgroud)

我的dwt代码

[TemplateCallable()]
public string SetVariable(string variableName, string value)
    {
        //Remove the old variable and set the new variable
        if (_Engine.PublishingContext.RenderContext.ContextVariables.Contains(variableName))
        {
            _Engine.PublishingContext.RenderContext.ContextVariables[variableName] = value;
            return "Variable Modified Successfully";
        }
        else
        {
            _Engine.PublishingContext.RenderContext.ContextVariables.Add(variableName, value);
            return "Variable Added Successfully";
        }
    }
    [TemplateCallable()]
    public string GetVariable(string variableName)
    {
        //Get the varialbe
        if (_Engine.PublishingContext.RenderContext.ContextVariables.Contains(variableName))
            return _Engine.PublishingContext.RenderContext.ContextVariables[variableName].ToString();
        else
            return "Variable doesn't exist";
    }
Run Code Online (Sandbox Code Playgroud)

Nun*_*res 5

循环中变量的问题是众所周知的,甚至记录在案.

基本上,第一个循环已经在您设置变量时进行了评估,因此您将始终关闭一个循环.

  • 设置变量i = 0
  • 循环迭代1,i = null
  • 循环迭代2,i = 0
  • 循环迭代3,i = 1
  • 等等