Jekyll Constant Values plugin allows you to render constant values in the .html
files of your Jekyll project. This way, if you have words that you repeat a lot or words that are susceptible to changes (like the number of workers in your company), this plugin helps you to only have to modify the value in a single file.
This repository was created with learning porpouses only. You can always create a constants:
key into your _config.yml
and then use site.constants.foo.bar
in the .html
pages.
- Add the following to your site's Gemfile:
gem 'jekyll_constant_values', group: :jekyll_plugins
- Run
bundle install
in your command line:
$ bundle install
- Create a new YAML file called
constants.yml
under your_data/
folder. If you prefer, you can customize the name of the file (must be also under_data/
) and put the name of your custom file without the extension in your_config.yml
file this way:
constants: your-custom-name
- Fill your constants YAML file with the content you need:
company_name: Group Hirthe-Ritchie
contact:
phone: (186)285-7925
address: 282 Kevin Brook
workers: 150
- Use
{% const [key] %}
Jekyll tag to render the content you need in the.html
files:
<h3>{% const company_name %}</h3>
<p>We are more than {% const workers %} workers in our company located in {% const contact.address %}.</p>
<a href="tel:{% const contact.phone %}">Call us</a>
- After rendering the previous example, you will see the following code in the
.html
file:
<h3>Group Hirthe-Ritchie</h3>
<p>We are more than 150 workers in our company located in 282 Kevin Brook.</p>
<a href="tel:(186)285-7925">Call us</a>
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
The gem is available as open source under the terms of the MIT License.