Is it possible to convert an integer to a value that can be "foreach"ed through?
Using razor, is it possible to convert a single-digit value to something that can dynamically generate content on a page?
For example, I want to show an image x number of times based off a value inputed in an Umbraco field. If the number "3" is typed into the field, I want to show the image 3 times. If the number "5" is typed, 5 times, and so on.
I've done a bit of googling and haven't found anything that gives me the correct results, i.e., something that cleanly translates the number "5" into "show this content 5 times".
This example will render 5 lines saying "Line 1", "Line 2" etc.
In the above you will of course need to replace the paragraph with your HTML for the image rendering and where it says 5 you will need to render the number value from your umbraco document type.
I hope this example makes sense and is enough to get you going? :)
Is it possible to convert an integer to a value that can be "foreach"ed through?
Using razor, is it possible to convert a single-digit value to something that can dynamically generate content on a page?
For example, I want to show an image x number of times based off a value inputed in an Umbraco field. If the number "3" is typed into the field, I want to show the image 3 times. If the number "5" is typed, 5 times, and so on.
I've done a bit of googling and haven't found anything that gives me the correct results, i.e., something that cleanly translates the number "5" into "show this content 5 times".
Hi Marie
You should be able to use a for loop like this
This example will render 5 lines saying "Line 1", "Line 2" etc.
In the above you will of course need to replace the paragraph with your HTML for the image rendering and where it says 5 you will need to render the number value from your umbraco document type.
I hope this example makes sense and is enough to get you going? :)
/Jan
That works perfectly, Jan! Thanks so much!
is working on a reply...