"assetModel_styleCss_handler" for JS

ShadowdareShadowdare Moderator

We can use the assetModel_styleCss_handler to include a "CSS file in all non-Dashboard pages" (not admin back-end pages).

Is there a similar one for including JS files? If not, what's a good way to only include JS files on the front-end?

One way I like is if ($sender->MasterView !== 'admin').

Add Pages to Vanilla with the Basic Pages app


  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Can't you simply base render ?

    $sender->addJsFile(asset('cache/pluginname/'.c('pluginname.configname').'.js', true));

  • ShadowdareShadowdare Moderator
    edited September 2016

    The base_render_before event code is run in the admin dashboard too. This is where putting the addJsFile() or addCssFile() calls within a if ($sender->MasterView !== 'admin') block would do the trick. I forgot to clarify where I'd use this in the first post.

    I'm looking for an event like assetModel_styleCss, which adds CSS only to non-admin pages, for JS.

    Add Pages to Vanilla with the Basic Pages app

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    // Adds the Js to every page except the dashboard.
        public function base_render_before($sender) {
            if ($sender->MasterView == 'admin' ) {
    $sender->addJsFile(asset('cache/pluginname/'.c('pluginname.configname').'.js', true));     
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    You can add js files like that:

        public function assetModel_styleCss_handler($sender, $args) {

    but using base_render_before is much more common.

  • I have opened an issue about a JS-event similar to styleCSS before:

    I believe this is going to be unified at some point when asset minification is going to arrive in the core.

    My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations

    • Vanilla APP » Learn more «
    • iOS & Android App for Vanilla - White label app for your forum
  • ShadowdareShadowdare Moderator
    edited September 2016

    @R_J, although JS files can be added in assetModel_styleCss, the documentation only shows it being used for CSS, so another event may be added for JS files. @Bleistivt, I believe it probably is going to be used for asset minification, too.

    I recall that a experimental config setting was added in Vanilla to enable asset minification, but haven't seen any updates about the feature.

    Add Pages to Vanilla with the Basic Pages app

  • LincLinc Director of Development Detroit Vanilla Staff

    I know minification is on the roadmap for ops, but I don't know the details of how it will be implemented or the specific constraints surrounding it.

Sign In or Register to comment.