循环和TemplateRepeatIndex在Dreamweaver模板(Looping and T

2019-06-23 17:25发布

我有一些麻烦变量的访问,这里在这种情况下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 -->

产量

Variable Added Successfully
Inline Value 0 
Inside Loop Value Variable doesn't exist 

我载重吨代码

[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";
    }

Answer 1:

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

基本上,第一循环已经被你设定变量的时间计算,所以你总是会被一个关闭。

  • 设定变量i = 0
  • 循环迭代1,I =空
  • 循环迭代2,则i = 0
  • 循环迭代3,I = 1
  • 等等


Answer 2:

这可能帮助: http://www.tridiondeveloper.com/get-and-set-variables-in-dwts



文章来源: Looping and TemplateRepeatIndex in Dreamweaver template