2012-04-18 12 views
6

Mam problem z dostępem do zmiennych, tutaj w tym przypadku Ustaw zmienna. Kiedy wchodzę do pętli, zmienna nie istnieje. Każdy ma wgląd w to. Doceń swoją pomoc:Zapętlanie i TemplateRepeatIndex w szablonie Dreamweaver

Poniżej znajduje się sekcja z moim kodem w szablonie. Czy mógłbyś pomóc, kiedy masz szansę? Dzięki.

<!-- 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 --> 

Wyjście

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

Mój kod 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"; 
    } 

Odpowiedz

5

Problemy ze zmiennych w pętli są dobrze znane i nawet documented.

Zasadniczo pierwsza pętla jest już oceniana przed ustawieniem zmiennej, więc zawsze będzie wyłączona przez jedną.

  • Zestaw zmienna i = 0
  • iteracji 1, I = NULL
  • iteracji 2 i = 0
  • iteracji 3, i = od 1
  • itp
+0

Dziękuję Nuno za informację. To pomaga! –

+0

Możesz wtedy oznaczyć go jako odpowiedź, więc pomaga innym osobom z tym samym pytaniem. –