Depends on the umbraco version, cause the latest version have a better Razor support for uComponents datatypes. Can't find any example code atm, but to get you started (quick win), you could introduce a flag to indicate whether you've already processed an item and if flag is set to true, just don't output the <li> block?
I'm sure there's better solutions out there...
@{ var processed = false; } <ul> @foreach (var x in Model.kursusHvornaar) { if (!processed) { <li>@x.InnerText</li> processed = true; } } </ul>
thanks for that - I got it working! with the example above.
If anyone is curious I wanted to loop through a uComponents textString array and have different loops for different languages. might be a bit of a silly way of doing things. I tend to do things arse about face sometimes :)
Can you explain how you're getting each cell with Textstring Array? The example above is for Multiple Textstring which only has one value per row. I can't seem how to figure out how to get each "cell"/value using Textstring Array such as in your screenshot.
I thought it would be something like:
foreach (var time in Model.homeServiceTimes) { <p>@time.value[0].InnerText</p> <p>@time.value[1].InnerText</p> }
but this throws an error: 'char' does not contain a definition for 'InnerText'
Thanks Tim, that does the trick. Although I think there must be an easier way to do it. In my current situation I want to write something like this for each row in the array
<strong>Cell 1:</strong> Cell 2<br/>
I think with your code above I'd need to add another counter in the inner loop and test to know when to use the strong. I would think I should be able to do something like
foreach (var qLoop in item.questionContent) { <strong>@qLoop.value[0] : </strong>@qLoop.value[1]<br/> }
But I can't figure out how to do that. Any ideas? But your code has got me started for now, thanks :)
@foreach value of Multiple Textstring - uComponents
I have some values from uComponents Multiple Textstring
and I cannot foreach et out in Razor
please help!
/Johan
Hi,
Try this:
Hope this helps.
Regards;
/Dirk
Thank you Dirk
the magic word is InnerText
you just made my night.
have spent some time and I can not search from google into our?!
/Johan
Hi Dirk,
thanks for your info here.
Just one more question: Would there also be an XSLT-variant to getting these values from a Multiple textstring?
/Jan
use this link it should be the same... almost.
/Johan
Um, how would you only output the first value and not the second?
so in the example above you only wanted to output
4. - 5. april 2011
and not
24. - 25. oktober 2011
tim,
Depends on the umbraco version, cause the latest version have a better Razor support for uComponents datatypes. Can't find any example code atm, but to get you started (quick win), you could introduce a flag to indicate whether you've already processed an item and if flag is set to true, just don't output the <li> block?
I'm sure there's better solutions out there...
Cheers,
/Dirk
Hey Dirk, am using 4.7.1 with uComponents 3.0
thanks for that - I got it working! with the example above.
If anyone is curious I wanted to loop through a uComponents textString array and have different loops for different languages.
might be a bit of a silly way of doing things. I tend to do things arse about face sometimes :)
Hey Tim,
Can you explain how you're getting each cell with Textstring Array? The example above is for Multiple Textstring which only has one value per row. I can't seem how to figure out how to get each "cell"/value using Textstring Array such as in your screenshot.
I thought it would be something like:
but this throws an error: 'char' does not contain a definition for 'InnerText'
Can you share how you achieved this?
Thanks,
Tom
Hi Tom,
I'm doing the following:
Hope that helps!
Thanks Tim, that does the trick. Although I think there must be an easier way to do it. In my current situation I want to write something like this for each row in the array
<strong>Cell 1:</strong> Cell 2<br/>
I think with your code above I'd need to add another counter in the inner loop and test to know when to use the strong. I would think I should be able to do something like
But I can't figure out how to do that. Any ideas? But your code has got me started for now, thanks :)
-Tom
...could have sworn I tried this, but I guess not. This works fine:
Thanks again!
Tom
Hi Tom,
Am having some issues displaying the first value of a multipleTextString in v4.9.1.
Hi Fuji,
I've not tested in 4.9, but looking at your code, it looks like you need to get the property somewhere, photos would be the doc/media item right?
-Tom
Nope did get this to work either.
But if i do something like
The one worked for me was:
@foreach(var x in Model.arrayPropertyAlias) {
<strong>@x[0]</strong> <p>@x[1]</p>
}
is working on a reply...