Search code examples
meteoriron-routermeteor-blaze

How to enable or disable a template using a server variable?


What is the recommended way of disabling a template from loading in the client that depends on a boolean server variable?

I want to switch on/off certain features of a website whether if it's on staging or production, I am doing this with server variables, but I wonder what is the safest way to get this info on the client side, I wouldn't want to be possible to a client user to activate a certain functionality on the client side.

I'm using Blaze + iron router + no user accounts


Solution

  • Three possibilities:

    1. Create a utility collection that is automatically published to all users with Meteor.publish(null,function(){}). Include documents and keys that will control the UI. Disable client-side updates, except possibly from your admin panel.
    2. Add keys to the user object that control the UI. Make sure these are published to the client and then check them in your helpers.
    3. Create a utility collection that is indexed by userId and/or session id and that contains the required keys. Sync that to the server for the current user and/or session.

    It's always going to be preferable to synchronize the state of the server using pubsub rather than with repeated method calls. The former will be reactive, the latter will not.