2012-04-18 14 views
6

ここでは変数にアクセスする際にいくつかの問題があります。ここではSetvariableです。ループの中に入ると、変数は存在しません。誰でもこれについての洞察を持っています。あなたのお手伝いをよろしくお願いいたします。DreamweaverテンプレートのルーピングとTemplateRepeatIndex

以下はテンプレートのマイコードセクションです。あなたはチャンスを得るときに助けてくれますか?ありがとう。

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

答えて

5

よく知られているループの変数の問題、さらにはdocumented

基本的に最初のループは、変数を設定した時点で評価されているため、常に1になります。

  • 設定変数i = 0
  • ループ反復1、I =ヌル
  • ループ反復2、I = 0
  • ループ反復3、I = 1
  • など
+0

ヌノさんに情報ありがとうございました。それは助けて! –

+0

それを答えとしてマークすると、同じ質問の他の人に役立ちます。 –