Developer forum

Forum » Templates » GetString from string with concat variable

GetString from string with concat variable

António Ramos
Reply

Hi guys,

There is any limitation to get a field with GetValue/GetString  from a variable?

e.g:

for(var i = 1; i <= 10; i++){

  string test = "Ecom:Product.Image."+@i+".Clean";

  @GetString(test)

}

I also tried:

@GetString(string.Format("Ecom:Product.Image.{0}.Clean", i.ToString()))

@GetString("Ecom:Product.Image.\"@i\".Clean")

 

Best Regards,

António Ramos

 

 


Replies

 
Mikkel Ricky
Reply
This post has been marked as an answer

For performance reasons some template values are only set if you explicitly use them in the template, i.e. "Ecom:Product.Image.7" will only have a value if you explicitly use it in the template. In your examples you do not explicitly use "Ecom:Product.Image.7" and therefore the underlying value is not available in the template.

To make your example work, the only workaround is to make sure that all template value names explicitly exist in your template. You can do this by adding a Razor comment like this in your template:

@* Ecom:Product.Image.1 Ecom:Product.Image.2 Ecom:Product.Image.3 … Ecom:Product.Image.10 *@

It's a hack, but it works.

Best regards,
Mikkel

Votes for this answer: 1
 
António Ramos
Reply

Hi Mikkel,

Thanks for your answer... it works.

Best regards,

António Ramos

 

You must be logged in to post in the forum