Allow HB to access to user-defined parameters in a theme's package.json file


#1

Hello,

I’m just starting with ghost + digital ocean, so I’m not sure if my request makes sense.

I’d really love to have the opportunity to customise a theme using a single entry point, if possible the package.json file (or any another file assigned to this), whereby user-defined parameters are made accessible using variable helpers (such as @config). Example use case:

1- Say I want to have tags:tag0,tag1,… featured on the front page. The only option is to edit index.hbs, and hard code the value as a filter parameter.
2 - Instead, allow theme developers to provision a variable in mytheme/package.json, where:

  "config": {
    "posts_per_page": 10,
    "featured_tags":"tag0,tag1"
  }

and provide access to that variable as HB using @config.tags_index, so that it can be reused in filter="{{@config.featured_tags}}".

Other example:

1- Say I want to test or change a subset of css assignments. One option is to directly alter the css file (screen.css), but that’s not adequate, as once those changes are made, it’s very difficult to keep track of them, and to roll them back.

2- Instead, using the same trick as above, the hbs and css code don’t change :

<h1 class="{{@config.my_css_title_h1}}">{{title}}</h1>

while package.json is updated from

  "config": {
    "posts_per_page": 10,
    "my_css_title_h1":"foobar"
  }

to

  "config": {
    "posts_per_page": 10,
    "my_css_title_h1":"barfoo"
  }

Benefit: This allows to define a system base line (css + hbs files), and make alterations or test variations without changing it. In the current ghost development stage, one as to continuously make changes to multiple files, and the baseline is never stable. In case of a problem, it’s very tedious to go back to a known good state.

With the example above, once the baseline is defined, I can return to a known good state by changing two lines in package.json, while currently, I’d have to alter the css file, and the hbs files everywhere the featured_tags list is used.

thanks!