Question

I would like to do something like the following with spark.

<viewdata model="IList[[string]]" />

<for each="var file in Model">
<use import="${file}" />
</for>

This however, does not work because Spark is not evaluating the ${file} before it tries the import. This makes sense and I suspected it would not work, but how else could I do something like this.

Note: The model is a list of file names.

Was it helpful?

Solution

You can always use Html.RenderPartial():

<viewdata model="IList[[string]]" />

<for each="var file in Model">
  <% Html.RenderPartial(file); %>
</for>

Edit:

I don't believe there is much better way, but if you really don't writing RenderPartial, you can do it once. You'll have to create _useview.spark:

<viewdata file="string"/>
<% Html.RenderPartial(file); %>

and then use it like that:

#var views = new string[] { "View1", "View2" };
<for each="string file in views">
    <useview/>
</for>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top