【问题标题】:Looping and TemplateRepeatIndex in Dreamweaver templateDreamweaver 模板中的循环和 TemplateRepeatIndex
【发布时间】:2023-04-03 12:32:02
【问题描述】:

我在访问变量时遇到了一些问题,在本例中为 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 

我的 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";
    }

【问题讨论】:

    标签: dreamweaver tridion dwt dreamweaver-templates


    【解决方案1】:

    循环中的变量问题是众所周知的,甚至documented

    基本上,在您设置变量时,第一个循环已经被评估,所以您总是会落后一个。

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

    【讨论】:

    • 您可能希望将其标记为答案,以便帮助其他有相同问题的人。
    【解决方案2】:

    【讨论】:

    • 感谢 Bappi 抽出宝贵时间。我使用了 tridiondeveloper 的相同代码,但没有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-25
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    相关资源
    最近更新 更多