views:

76

answers:

1

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.

A: 

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>
LukLed
That does work. We had figured that out already, but we were wondering if there was a way to do it with Spark specifically. If I don't get any better answers using Spark I'll mark you as the answer. Thanks for submitting!
Ryan Montgomery
Does this hack with empty useview tag really work? From what I see in spark google groups, all the views are put together at compile time. They also do not suggest anything except RenderPartial.
queen3
It works. It is the same as upper solution, but RenderPartial is moved to partial view. for each 'file' variable is visible in scope of '_useview'. Spark generated view code is the same in both solutions.
LukLed