Does SSVE support nested iterators?
I am looking to walk down an object graph in my SSVE view (see below) but I suspect that nested iterators are not the way to go here. Is there another approach?
I know SSVE was intended for internal use and is not meant for full production use, so no problems, but I don't want to add an reference to Razor and mess up my web.config file unless I absolutely have to.
Nested Iterator View (my best guess)
@Master['_Master']
@Section['Content']
<h1>Assessment - @Model.survey.title</h1>
@Each.survey.pages
<div>
<h2>@Current.title</h2>
@Each.questions
<div>@Current.title</div>
@EndEach
</div>
@EndEach
@EndSection
This question is quite old now, but still crops up as the top search result on Google for nested each using the Super Simple View Engine. In case anyone else runs into this, know that support for Partial Views within an Each has been added to SSVE. (I've used it to do exactly this kind of View nesting - iterating over collections within collections.)
So you can achieve the effect you want using two Views, where the outer one looks like this:
@Master['_Master']
@Section['Content']
<h1>Assessment - @Model.survey.title</h1>
@Each.survey.pages
<div>
<h2>@Current.title</h2>
@Partial['QuestionList', Current.questions]
</div>
@EndEach
@EndSection
And then the other View (which SSVE will find with the name QuestionList) looks like this:
@Each
<div>@Current.title</div>
@EndEach
Though it leads to quite a few files, you should be able to get to arbitrary depth by repeating this pattern.
No, that won't work - SSVE is essentially just a regex. It should support a partial inside an each, but currently it doesn't.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With