Using the Cassette V2 to compile templates jsRender and KnockoutJS templates

363 views Asked by At

I am moving to version 2 of the Cassette.

But I found nothing on the web to help me configure my Cassette to compile HTML templates.

Templates

Some templates jQuery Templates as:

<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="header" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="header">${header}</h3>
    </div>
    <div class="modal-body">
        {{html body}}
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal">${CancelText}</button>
        <button class="btn ${ClassBtn}">${ConfirText}</button>
    </div>
</div>

I will modify them for use jsRender soon!

Others as KnockoutJS

<div class="span2">
    <div class="data-block">
        <h4 data-bind="text: Total"></h4>
        <h6>
            <span data-bind="text: Passo.Nome"></span>
            <small class="muted" data-bind="text: Passo.Responsavel">Riderman de Sousa</small>
        </h6>
    </div>
</div>

IConfiguration<BundleCollection> class

bundles.AddPerSubDirectory<HtmlTemplateBundle>("HtmlTemplates", b => b.Pipeline = ??? );
1

There are 1 answers

0
Joe On

I actually found the answer, with v2 everything is seperated. So if you use Less you have to get the Cassette.Less nuget package. Same with the tmpl items.

1 ) Get the Nuget Package: http://nuget.org/packages/Cassette.KnockoutJQueryTmpl/2.0.0

2 ) Configuration:

public class CassetteConfiguration : IConfiguration<BundleCollection>
{
    readonly KnockoutJQueryTmplPipeline pipeline;

    public CassetteConfiguration(KnockoutJQueryTmplPipeline pipeline)
    {
        this.pipeline = pipeline;
    }

    public void Configure(BundleCollection bundles)
    {
        bundles.Add<StylesheetBundle>("Content", new FileSearch { Pattern = "*.css;*.less", SearchOption = System.IO.SearchOption.AllDirectories });
        bundles.Add<ScriptBundle>("Scripts");
        bundles.AddPerIndividualFile<ScriptBundle>("Content/js");

        bundles.Add<HtmlTemplateBundle>("HtmlTemplates", new FileSearch { Pattern = "*.htm" }, b => b.Pipeline = pipeline);
    }
}

3 ) Reference the bundle in your View

Bundles.Reference("HtmlTemplates");