Make Sure Your Resource Records Are Present

Phillipp
Bolt CMS
Published in
3 min readJan 22, 2016

Sometimes your theme needs specific information besides the normal content. Short text snippets or social media usernames for example.

In Bolt, it’s best practice to create key-value-like resource contenttypes for those kinds of things. Well, you could also store them in your config file but resource contenttypes give a much better user experience for clients.

Let’s continue with an example about social media usernames you want to link in the footer of your template. Your resource contenttype could look like this:

social:
name: Social Media
singular_name: Social Media
fields:
title:
type: text
class: large
slug:
type: slug
uses: title
name:
type: text
default_status: published
show_on_dashboard: false
searchable: false
viewless: true

This allows you to create one record per social network and use them like this:

{% setcontent twitter = 'social/twitter' %}
{% setcontent github = 'social/github' %}
<a href="https://twitter.com/{{ twitter.name|raw }}">Twitter</a>
<a href="https://github.com/{{ github.name|raw }}">Github</a>

The Problem

The above example assumes you have a record with the slug ‘twitter’ and another with the slug ‘github’.

Depending on your workflow, you may have your local development environment, a staging server and a production server. Maybe an automated deployment too.

This means you have to create the above two records on all systems by hand, so your client can edit them. And if you add another one like ‘facebook’, you have to update all three environments again.

With three records this isn’t a big deal but what if your theme depends on 10 or 20 different resource records? A way to automate this would be awesome, right?

The Solution

Today is your lucky day! I have built an extension that does exactly this! You can find it on Github and in the Bolt Extension Store.

I’ll skip the installation and continue with the configuration. It’s as simple as adding a ‘require’ key to the contenttype.

social:
name: Social Media
singular_name: Social Media
fields:
title:
type: text
class: large
slug:
type: slug
uses: title
name:
type: text
required:
- slug: twitter
title: Twitter
- slug: github
title: Github
default_status: published
show_on_dashboard: false
searchable: false
viewless: true

Now browse to ‘Extras’ => ‘Required Records’ to see an overview of all your required and missing records.

Here you can see we require the ‘twitter’ and ‘github’ records in the ‘social’ contenttype and that they’re not present yet. You can create them by hitting the ‘Add Records’ button.

That’s all! Just one click and they are all created.

Well, they don’t have the important content yet, but your client can see and fill them with content.

If you use an automated deployment, you can execute the ‘app/nut required-records:create’ command to create all missing records.

I hope this extension helps you to save some time. If so, let me know in the comments or in the Bolt Slack Channel. :)

--

--