passing a configuration variable to a swig based server views


VikramTiwari a seasoned user is working on a material design package for mean.

Just like you can choose between coke or pepsi or between pizzahut or dominos It would sure be cool if we could choose our preffered css framework.

Currently bootstrap is hardcoded all over the place and in PR 1290 he wanted to move the hardcoding in to the aggregation, emps (another experienced mean developer) mentioned that having bootstrap available early on (before all of the aggregated css/js is loaded) will let us display the basics (layout/fonts) before aggregation is loaded and the rest cones in to place.

To achive this I need to “Ask” in the packages/core/system/server/views/incules/head.html what is the prefered cssFramework and to display the correct css in the head based on that configuration.

config to server view

So now I need to define a configuration value called cssFramework and to somehow get it to my serverside express routes I did this in a commit today and wanted to share…

  1. Define the value in configuration – I chose to put it in config/env/all.js because this value will probably be valid across all enfironments.
  2. Pass System to the rendered view in packages/core/system/server/routes.js
  3. Changed the controllers code to be able to accept a paramater (in this case it’s the config).
  4. Use the variable in your view (in this case just a comment).

Hope this helps people that want to use server side variables and configuration…

  • Fernando Santucci

    I think that my project, as well as many others, is using mainly Material Design, but there is some third-party Angular directives based in Bootstrap not covered by MD, then both CSS frameworks and directives need to be actives.

    The PR #1290 – “moved bootstrap from head to assets as dependency” was made to separate the implementation of frameworks, but it allows you to implement both frameworks?