# Allow config variables for Themes

**URL:** <https://forum.ghost.org/t/allow-config-variables-for-themes/20991>\
**Category:** Themes\
**Created:** [March 20, 2021, 9:54am UTC](https://forum.ghost.org/t/allow-config-variables-for-themes/20991 "2021-03-20T09:54:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DoogieMuc](https://avatars.discourse-cdn.com/v4/letter/d/4bbf92/32.png) [@DoogieMuc](https://forum.ghost.org/u/DoogieMuc)\
**Post date:** [March 20, 2021, 9:54am UTC](https://forum.ghost.org/t/allow-config-variables-for-themes/20991/1 "2021-03-20T09:54:20Z")

</div>

reopening this post:

> [@Accessing a theme's package.json variables](https://forum.ghost.org/t/accessing-a-themes-package-json-variables/4819):
>
> Hi there, Can anyone share a link explaining how to access the config variables of a theme’s package.json, unsing handlebars (or anything adequate to process those values in an .hbs file)? It surely is possible since: “config”: { “posts\_per\_page”: 10 } is used. thanks!

This can easily be solved. See this pull request:

> <https://github.com/TryGhost/Ghost/pull/12797>
>
> ….json
> 
> Provide a way so that theme authors can make their themes configurable….
> For example: A theme might offer the possibility to optionally show a tag cloud. 
> There should be a way so that the theme user can easily configure this.
> 
> And actually there already would be such a way. It's just simple forbidden in the current code. There already is a \`config\` section in the themes package.json But the code filters and only allows the attributes \`posts\_per\_page\` \[as documented\](https://ghost.org/docs/themes/helpers/config/) and \`image\_sizes\`. Themes can directly access these variables as \`{{@config.posts\_per\_page}}
> 
> Why restrict this to just these two variables. Allow any variables for theme authors.
> 
> Got some code for us? Awesome 🎊!
> 
> Please include a description of your change & check your PR against this list, thanks!
> 
> \- \[\] There's a clear use-case for this code change
> \- \[\] Commit message has a short title & references relevant issues
> \- \[\] The build will pass (run \`yarn test\` and \`yarn lint\`)
> 
> More info can be found by clicking the "guidelines for contributing" link above.

Provide a way so that theme authors can make their themes configurable.  
For example: A theme might offer the possibility to optionally show a tag cloud.  
There should be a way so that the theme user can easily configure this.

And actually there already would be such a way. It’s just simple forbidden in the current code. There already is a `config` section in the themes package.json But the code filters and only allows the attributes `posts_per_page` [as documented](https://ghost.org/docs/themes/helpers/config/) and `image_sizes` . Themes can directly access these variables as `{{@config.posts\_per\_page}}

Why restrict this to just these two variables. Allow any variables for theme authors.

---

<div class="post-metadata">

**Author:** ![vikaspotluri123](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/vikaspotluri123/32/24_2.png) [@vikaspotluri123](https://forum.ghost.org/u/vikaspotluri123)\
**Post date:** [March 20, 2021, 5:24pm UTC](https://forum.ghost.org/t/allow-config-variables-for-themes/20991/2 "2021-03-20T17:24:47Z")

</div>

> [@DoogieMuc](#):
>
> Why restrict this to just these two variables. Allow any variables for theme authors.

This was answered in a different PR that does something very similar to what your PR does:

> <https://github.com/TryGhost/Ghost/pull/11044#issuecomment-523304745>
>
> Thanks for the PR 😄 
> 
> There was a really nice proposal done around this here: …https://github.com/TryGhost/Ghost/issues/9375 but it missed two things
> 
> 1) multiple clear use cases
> 2) consideration of implications (e.g. how can this be misused?)
> 
> I've seen this proposal of adding config this way pop up a few times, but it's one of those things where people jump to a solution but we've not had chance to fully understand what the problems are that it's meant to solve. 
> 
> Would love to hear more about your use cases and problems you've encountered. 
> 
> Until it's clear that this is a) the best solution to a genuine problem and b) safe, it's not something we would add.

---

<div class="post-metadata">

**Author:** ![DoogieMuc](https://avatars.discourse-cdn.com/v4/letter/d/4bbf92/32.png) [@DoogieMuc](https://forum.ghost.org/u/DoogieMuc)\
**Post date:** [March 20, 2021, 6:52pm UTC](https://forum.ghost.org/t/allow-config-variables-for-themes/20991/3 "2021-03-20T18:52:46Z")

</div>

You do receive the same feature request multiple times. Each time given with a elaborate description of the use case. (By me and also the former authors in the PR that you linked).

The Feature request can be implemented by deleting two lines of code.

And you dare to ask WHY ?!?!?

(To repeat the requirement: To give theme authors a way of easily making their theme _configurable_)

---

<div class="post-metadata">

**Author:** ![denvergeeks](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/denvergeeks/32/7401_2.png) [@denvergeeks](https://forum.ghost.org/u/denvergeeks)\
**Post date:** [March 20, 2021, 8:28pm UTC](https://forum.ghost.org/t/allow-config-variables-for-themes/20991/4 "2021-03-20T20:28:11Z")

</div>

@DoogieMuc I’m not sure if this will help or not, because (not being a coder) I don’t yet fully understand the pertinent infrastructures of the code to this issue. Having said that, I am very pleased to find and use the many examples of existing themes that do provide what (I think 🤔 ) you are describing.

These themes provide for the setting of variables as bits of JavaScript in the (Site, Page, and Tag) Header Code Injection areas in the Admin UI.

One such example is the Fizzy Theme:

> **[GitHub - huangyuzhang/Fizzy-Theme: 🥤A tasty blogging theme for Ghost.](https://github.com/huangyuzhang/Fizzy-Theme)**
>
> 🥤A tasty blogging theme for Ghost. Contribute to huangyuzhang/Fizzy-Theme development by creating an account on GitHub.

I have found many others, and would highly value and appreciate a tutorial on the best way to implement this method.

---

<div class="post-metadata">

**Author:** ![DoogieMuc](https://avatars.discourse-cdn.com/v4/letter/d/4bbf92/32.png) [@DoogieMuc](https://forum.ghost.org/u/DoogieMuc)\
**Post date:** [March 21, 2021, 10:40am UTC](https://forum.ghost.org/t/allow-config-variables-for-themes/20991/5 "2021-03-21T10:40:28Z")

</div>

Thank you, this is actually a nice idea.  
Sadly it’s only a workaround. But one that fits for most use cases.

The “Code Injection” of the admin UI injects code into the _client side_ javascript. This code will be executed at the client, when a visitor visits the page. This code can hide elements of the page. But still those elements need to have been loaded.

For hiding a small tag cloud that’s ok. It doesn’t matter if that few bytes are loaded for nothing and then hidden.

I’ll keep looking …

---

<div class="post-metadata">

**Author:** ![John](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/john/32/29288_2.png) [@John](https://forum.ghost.org/u/John)\
**Post date:** [March 21, 2021, 2:07pm UTC](https://forum.ghost.org/t/allow-config-variables-for-themes/20991/6 "2021-03-21T14:07:15Z")

</div>

We’re looking at ways to support theme settings natively in Ghost 🙂 watch this space. No roadmap or timeline yet, but we’re listening. Thanks for your patience. We often take a little longer than usual to implement things, because we spend more time to try and make sure we really get the underlying architecture right.

If you rush features with a poorly executed fundamental architecture and then allow a developer ecosystem to be built on top of it, well that’s how you end up with ~~ants~~ WordPress
