2012-04-18 12 views
6

Tengo problemas para acceder a las variables, aquí en este caso Setvariable. Cuando ingreso al ciclo, la variable no existe. Alguien tiene alguna idea sobre esto. Agradezca su ayudaLooping y TemplateRepeatIndex en la plantilla Dreamweaver

A continuación se encuentra la sección de mi código en la plantilla. ¿Podrías por favor ayudar cuando tienes la oportunidad? Gracias.

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

salida

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

Mi código de toneladas de peso muerto

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

Respuesta

5

Problemas con las variables en los bucles son bien conocidos e incluso documented.

Básicamente, el primer ciclo ya está evaluado para cuando configura su variable, por lo que siempre estará apagado en uno.

  • variable de Set i = 0
  • bucle de iteración 1, i = null
  • bucle de iteración 2, i = 0
  • bucle de iteración 3, i = 1
  • etc
+0

Gracias Nuno por la información. ¡Eso ayuda! –

+0

Puede marcarlo como la respuesta, entonces ayuda a otros con la misma pregunta. –