2012-04-18 1 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.

기본적으로 첫 번째 루프는 변수를 설정할 때 이미 평가되므로 항상 하나씩 꺼야합니다.

  • 설정 변수 I = 0
  • 루프 반복 1, I = NULL
  • 루프 반복 (2), I = 0
  • 루프 반복 3, I = 1
+0

정보에 대해 누노에게 감사드립니다. 그게 도움이! –

+0

그러면 답으로 표시하여 동일한 질문을하는 사람들을 도울 수 있습니다. –