MiroHibler / meteor-preloader

A Meteor "lazy-loader" for external .js and .css libraries
75 stars 3 forks source link

How do I load one JS file and one CSS file to a specific route/template without configuring all the other options? #11

Closed WilliamHua closed 9 years ago

WilliamHua commented 9 years ago

How do I load one JS file and one CSS file to a specific route/template without configuring all the other options?

MiroHibler commented 9 years ago

All you have to do is:

// The simplest case; add other parameters to the route as you wish
Router.route( '/', {
    controller: PreloadController,
    'preload': {
        'styles': '/plugins/yet_another_fancy_schmancy.css',
        'sync': '/plugins/yet_another_fancy_schmancy.js'
    }
});

Basically, all options are... well, optional ;) Try to play with them and see what happens :)

WilliamHua commented 9 years ago

Awesome thank you!

From what I understand, to load a template that has a different name than route you typically do something like:

Router.route('/', function(){
    this.render("templateName"); 
});

How would you combine that with pre-loader?

MiroHibler commented 9 years ago

Your assumption is right. Equally, for example, you can do:

Router.route( '/', {
    name          : 'home',
    template      : 'main',
    yieldTemplates: {
        'news': {
            to: 'mainContent'
        }
    },

    /*
     | If no extended controller has been provided for a particular route,
     | a PreloadController itself should be assigned to the route
     */
    controller: PreloadController
});