I'm not sure you'd ever be able to do that with the <use file="">
mechanics. The way partials are imported is generating all of the code
chunks in-place, so it'd never be practical to include all of the
possibilities...
If there was a known set of templates you could always include them
statically and use the templateToRender as a selector...
<use file="foo" if="templateToRender='foo'"/>
<use file="bar" elseif="templateToRender='bar'"/>
<use file="quux" elseif="templateToRender='quux'"/>
<use file="quad" elseif="templateToRender='quad'"/>
<else><% throw new ApplicationException("Unknown templateToRender: " +
templateToRender); %></else>
or if they start with underscores it could also be written:
<foo if="templateToRender='foo'"/>
<bar elseif="templateToRender='bar'"/>
<quux elseif="templateToRender='quux'"/>
<quad elseif="templateToRender='quad'"/>
<else><% throw new ApplicationException("Unknown templateToRender: " +
templateToRender); %></else>
If you're looking for something that's literally dynamic... Maybe make
a view component and pass the template to render as a parameter? You
could use that param in the call to RenderView.
<Module viewname="templateToRender"/>
class ModuleComponent : ViewComponent
[parameter] public string viewname{get;set;}
public void Render()
{
RenderView(viewname);
}
which would restrict you to having all of your views located at:
/views/components/module/*.spark
Asp.Net MVC has Html.RenderPartial(viewname) of course, but other than
with a viewcomponent-renderview I'm not sure what else you would do in
monorail to have the same result.
Any of those seem reasonable? I guess you could also make a helper
that reaches back into the view engine to render a view and return it
as a string. Probably bump into a lot of complex internals getting
that route to work.