Contribute to Docs Contribute to Docs

Resources

When building custom modules, or adding application specific views into the manager interface you might need to inject your own css or javascript files. You can add any number of resources, and they will be added to the main Layout of the manager interface in the order you add them.

When accessing the Manager module (or any module), make sure you do it after it has been added and initialized. Modules are usually added from within ConfigureServices, and they are initialized when Piranha.App.Init() is called.

Adding Stylesheets

The stylesheet collection can be accessed from the Styles property. This collection holds all custom stylesheets that has been added by your own code, or other modules. Please note that you can not access the default styles of the interface this way. Below is an example of how to add a custom stylesheet to the collection.

using Piranha;

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    ...

    App.Modules.Manager()
        .Styles.Add("~/assets/css/mystyles.css");

    ...
}

Adding Scripts

The script collection can be accessed from Scripts property and work in the same way as the stylesheet collection. Below is an example of how to add a custom script to the collection.

using Piranha;

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    ...

    App.Modules.Manager()
        .Scripts.Add("~/assets/js/myscripts.js");

    ...
}

A Note On Rendering

Like in most web applications, the stylesheets are rendered in the head section in the top, while the scripts are rendered in the end of the body tag.