Is it possible to have a template with html content in vm for a block component?
I'm doing a lot of stuff in html, and want the html reside in a .vm, not in codebehind.
Here is what i've got:
public class TwoColumn : ViewComponent
{
public override void Render()
{
RenderText(@"
<div class='twoColumnLayout'>
<div class='columnOne'>");
// Context.RenderBody();
Context.RenderSection("columnOne");
RenderText(@"
</div>
<div class='columnTwo'>");
Context.RenderSection("columnTwo");
RenderText(@"
</div>
</div>
");
}
}
Here is what i want to get: pageWithTwoColumns.vm:
#blockcomponent(TwoColumn)
#columnOne
One
#end
#columnTwo
Two
#end
#end
twocolumn/default.vm (pseudocode):
<div class="twoColumnLayout">
<div class="columnOne">
#reference-to-columnOne
</div>
<div class="columnTwo">
#reference-to-columnTwo
</div>
</div>
You have the
RenderView
method on the base class of the ViewComponent. what you can do is use the overload that writes the view in-place into a TextWriter.just stick this method in your viewcomponent and you should be done
I have finally found a solution using Ken's suggested StringWriter technique, but with different method. It's not RenderView, it's RenderSection
template:
I would suggest a feature for monorail, if you don't mind. It would be great to be able to reference the section from view template like this: