On every children add 1 (+1) Umbraco Razor -
in code below need add (+1) on every children on data-slide-index="0".
starting @ 0 , 1,2,3,4,5
it should this:
data-slide-index="0" data-slide-index="1" data-slide-index="2"
i thinking this.
int thecount = 0; thecount += 1; // adds 1 count
but dont know how use correctly in code.
@foreach (var image in @model.children) { foreach (dynamic d in image.imagedampsingle) { <a data-slide-index="0" href="@damp_helper.getimagecropperurl(d, "projectsingle")"><img src="@damp_helper.getimagecropperurl(d, "projectsinglethumb")" title="@model.captiontext" alt="@d.image.nodename" /></a>
or there easier / way this?
thanks in advance!
//rené
razor view engine, using c# code in there logic operation. recursive methods algorithmic operations have capability call until condition satisfied. can use helper in case achieve that. example case:
@helper dosomething(ienumerable<something> mylist) { foreach (var item in mylist) { @item.certainproperty @if (item.children.any()) { @dosomething(item.children) } } }
learn , read recursion, , whole new world of fundamental concepts appear.
http://en.wikipedia.org/wiki/recursion_(computer_science) http://learnyousomeerlang.com/recursion
it's fundamental topic, programming snippets right when read topic, where's other example in python:
def contavogais(cadeia): if not cadeia: return 0 return (1 if cadeia[0] in 'aeiou' else 0) + contavogais(cadeia[1:])
as can see examples, recursive solutions more elegant, but in cases might have decrease code performance.
Comments
Post a Comment