First of all, I am completely new to Umbraco and relatively new to MVC and Razor, so apologies if I come across as a complete noob...
One of my Document Types has a Multiple Textstring property called "Key Features".
On my template I want to loop through this property and display each textstring, comma-separating the list to make it read like a sentence. i.e. one comma between each item and no comma after the last item.
Here's my code fragment:
var counter = 1; foreach( var feature in property.AsDynamic().keyFeatures) { @feature if (counter < property.AsDynamic().keyFeatures.Length) { <span>,</span> } counter++; }
I am fairly sure there is a weird save bug when you've got an synatically invalid Razor macor that occassionaly you make a change - hit save, receive a confirmation but it doesn't change the macro. This might be what you saw (as the symptons match some of my own).. if you can you nail down the process I'd love to trap and report this bug (and convince myself I'm not going mad!).
foreach loop displays text separator twice?
First of all, I am completely new to Umbraco and relatively new to MVC and Razor, so apologies if I come across as a complete noob...
One of my Document Types has a Multiple Textstring property called "Key Features".
On my template I want to loop through this property and display each textstring, comma-separating the list to make it read like a sentence. i.e. one comma between each item and no comma after the last item.
Here's my code fragment:
The output is:
So the if statement handles the condition in the correct way, but why on earth is it outputting the <span> twice!!!
I'm really hoping this is a simple "you stupid noob, you should have done this" problem.
Cheers,
Simon
Stop the press! Now it suddenly works! I can't see what has occurred - my code is unchanged.
I published the page again, but previously changes to the template were being shown on screen.
(Everyone else walks away, rolling their eyes...)
I am fairly sure there is a weird save bug when you've got an synatically invalid Razor macor that occassionaly you make a change - hit save, receive a confirmation but it doesn't change the macro. This might be what you saw (as the symptons match some of my own).. if you can you nail down the process I'd love to trap and report this bug (and convince myself I'm not going mad!).
Thanks Steve, I'll be sure to keep a watchful eye out for similar issues.
is working on a reply...