Documentation

Bundles Helper

In views, use the Cassette.Views.Bundles helper class to reference bundles and render the required HTML.

Bundles.Reference(path) Adds a reference to bundle. The path can be to a bundle or one of its assets. It is relative to the application root, not the page.
Bundles.RenderScripts() Returns <script> elements for the referenced scripts.
Bundles.RenderStylesheets() Returns <link> elements for the referenced stylesheets.
Bundles.RenderHtmlTemplates() Returns the referenced HTML templates within special <script> elements.
Bundles.Url(bundlePath) Returns the Cassette URL of the bundle.

Ad-hoc URL References

References to URLs can also be added. Cassette will generate the relevant HTML along with the other bundles.

@{
    Bundles.Reference("http://www.example.com/some-resource.js");
}

Page Data Scripts

Passing data into a page for use by JavaScript is easy using the AddPageData method.

@{
    Bundles.AddPageData("globalData", new { username = User.Identity.Name });
}

This will add a <script> block to the page that creates a global variable containing the JSON serialized data.

Page Locations

Bundles can have an optional PageLocation assigned. This string allows certain bundles to be rendered in different parts of the page. For example, some scripts belong in the <head> and some just before </body>.

Use overloads of the Render* methods to specify the page location being rendered.

@Bundles.RenderScripts("body")

Inline Scripts

Ad-hoc inline page scripts can be managed by using the AddInlineScript method.

@{
    var message = "Hello World!";
    Bundles.AddInlineScript(
      @<text>
        alert('@message');
      </text>);
}

This will add a <script> block to the page that displays a whitty message to visitors.