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.


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.


Inline Scripts

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

    var message = "Hello World!";

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