Over the years I've looked at dozens of content management systems. A lot of them are very good. Some are very simple and others very complex with a ton of plug-ins and modules. Others are very easy to theme, but more difficult to access the backend. And the opposite is true with some having easy backend/database access, but limited theming capabilities. I've found few that have a good balance of complexity to feature set.

A while back I happened to discover Bolt. It's self-described as 'Easy for editors, and a developer's dream cms'. It's goal is to be as simple as possible, quick to setup, easy to configure and still be very feature rich.

bolt_cms.png

After using it on some of my own projects I have to say it has been a very pleasant experience and something I'd recommend if you want to break away from the pack and look at something different.

Bolt has modest requirements and uses the standard building blocks of a PHP (5.3.3 or higher) application. It supports Apache or Nginx although it comes ready to go for Apache so if you want the quickest and easiest install, go with Apache. By default is uses SQLite for the database backend, but it does support MySQL and PostgreSQL. I've personally used SQLite and MySQL confgurations of Bolt with no issues.

Installation:
There are two most common methods.

1) Installing from command line.

curl -O http://bolt.cm/distribution/bolt-latest.tar.gz
tar -xzf bolt-latest.tar.gz --strip-components=1

2) Or if you prefer a zip file, grab the latest version, unzip the files and upload to the target webserver directory.

A few directories need read/write permissions so be sure to chmod/chown correctly.

app/cache/
app/config/
app/database/
files/
theme/
extensions/

If you want to use a database other than SQLite you'll need to modify the app/config/config.yml file. All the files in app/config will end with .dist before you run the first time setup. Copy the config.yml.dist file to config.yml. Edit the database section in the config.yml file with the appropriate values. Be sure you've setup the database, username and password first.

database:
  driver: mysql
  username: bolt
  password: password
  databasename: bolt

Point your browser to the webserver and you'll be redirected to the first time setup to add the first user. This will be the admin user for the installation.

Username:
Password:
Email:
Display Name:

bolt_setup.png

After completing the initial setup, you'll be presented a login screen.

bolt_login.png

You can also go to the visit the front page by clicking the View site link in the top right of the screen.

website_initial.png

Once logged in, you'll see the main Dashboard. Time to look around and customize. You'll want to update the site name, payoff and setup a home page. This is done in the app/config/config.yml file which can be accessed from the Dashboard via Configuration -> Main configuration links. The default theme is looking for an about page so you can create one or modify the theme templates as necessary.

Before making changes to the default theme be sure to copy a new theme from the default base so you can customize your own copy without worry of losing it during an upgrade. You enable your own theme by modifying the theme directory name in the config.yml file.

bolt_initial_dashboard.png


Bolt in Action

The backend database:

One of the things I really like about Bolt is being able to manipulate the backend database outside of the Bolt interface itself. As long as you adhere to a few basic requirements for the Bolt schema, it's easy to add, delete or update any of the content you store. Bolt will happily manage it just as if you had used the interface to do this work. This is a very important since I don't have to worry about writing to an API. I can focus on the data and what I want to store with some basic (or maybe not so basic) SQL.

Let's take a look at how I do this. The first thing to do is create the content type with the desired fields you'll need to store the information. You'll use the Bolt interface to do this work. We'll use a SAN Switch with some basic attributes in this example. I'm using MySQL in this example as well.

Content Type: sanswitch
Fields:

 name (we'll map this to the title of the content)
 description (we'll map this to the body of the content)
 serial
 wwn
 type
 model
 ports
 status
 health

We need to create the content type. Login to bolt and select Configuration -> Contenttypes. This will open the contenttypes.yml file for editing.

setup_contenttype.png

There are several examples of field types you can use. Ours will look like this. We'll place this at the bottom of the file. Keep in mind there are some reserved field names (such as status) so we'll need to avoid those.

sanswitches:
    name: SANSwitches
    singular_name: SANSwitch
    fields:
        title:
            type: text
            class: large
        slug:
            type: slug
            uses: title
        body:
            type: html
            height: 300px
        serial:
            type: text
        wwn:
            type: text
        type:
            type: text
        model:
            type: text
        ports:
            type: integer
        switch_stat:
            type: text
        health:
            type: text
    record_template: entry.twig
    listing_template: listing.twig
    listing_records: 10
    default_status: publish
    sort: -datepublish
    recordsperpage: 10

Save the updates. Select Configuration -> Check Database. Bolt notices the new content type is not in the database and asks to update the database.

bolt_database_update.png

Select Update the database.

bolt_database_up_to_date.png

This content type becomes a new table in the Bolt MySQL database. In this case it will be bolt_sanswitches. You can see the new table in the database.

bolt_sanswitches_table.png

We can start adding SAN Switch entries in the Bolt interface, but I want to have some automation do all this work for me. Let's demonstrate a simple Perl script with DBI and SQL.

#!/usr/bin/perl

use DBI;

#Bolt format.
my $datetime="2016-04-23".' '."00:00:00";
 
#Connect to the Bolt database
############################################################################
$stodb="bolt";
$stoserver="localhost";
$stodbport=3306;
$stouser="bolt";
$stopw="password";
 
$dbh=DBI->connect("DBI:mysql:$stodb:$stoserver:$stodbport",$stouser,$stopw, {RaiseError => 1})
     or die "connecting: $DBI::errstr\n"; 

$title="switch01";
$slug="switch01";
$userid=1;
$body="This is switch01.";
$serial="AFX99092344";
$wwn="10:99:88:77:66:55:44:33";
$type="120";
$model="DCX-8510-8";
$ports=384;
$switch_stat="Online";
$health="Healthy";
 
#Add report
print "Adding $slug to database.\n";

$sqlcmd="insert into bolt_sanswitches \(title,slug,status,ownerid,templatefields,datechanged,datedepublish,datepublish,datecreated,body,serial,wwn,type,model,ports,switch_stat,health\) VALUES \(\"$title\", \"$slug\", \'published\', \"$userid\", \'[]\', \"$datetime\", null, \"$datetime\", \"$datetime\", \"$body\", \"$serial\", \"$wwn\", \"$type\", \"$model\", \"$ports\", \"$switch_stat\", \"$health\"\)";

if (!$dbh->do($sqlcmd)) {
   print "Error:" . $dbh->errstr . "\n";
}else{
   print "Record added to the database.\n"; 
} 

exit 0;

Run this script.

# ./bolt_insert_example.pl
Adding switch01 to database.
Record added to the database.

Now when we look at the Bolt Dashboard, the entry is shown there.

bolt_sanswitch_record.png

You can select it and look at all the other fields we added. If you look at the entry on the site screen however, you'll notice it only shows the body content.

bolt_switch01_website_initial.png

That's due to the fact we are using the default entry.twig template which only displays the body field. We'll fix that next.


The Frontend Templating System - Twig

Bolt uses Twig for templating and displaying data on your website. If you noticed by default we were using the entry.twig template for the sanswitches content type. We'll change this to one called sanswitch.twig. We'll start with a copy of entry.twig.

Before you begin modifying theme twig files, make a copy of the base-2014 theme. we'll call it bolt in this exercise.

From your bolt installation directory...

cd theme/bolt (or whatever name you called the theme you copied from the base-2014 theme)
cp entry.twig sanswitch.twig

Now go back into the Bolt Dashboard and update the SANSwitches content type to use the new sanswitch.twig template.

Change the record_template to the new name.

record_template: sanswitch.twig

Now that we have the sanswitch content type using the new twig template, we can make some changes to add the additional fields we created. I'll add some fields below the record.body section. We'll keep it simple. You'll want to do a lot more formating with some html/css in a real world setting. This gives you an idea of how twig templates let you display your data.


{{ record.body }}
<p>Serial number: {{ record.serial }}
<br>Type: {{ record.type }}
<br>Model: {{ record.model }}
<br>Total Ports: {{ record.ports }}
<br>Status: {{ record.switch_stat }}
<br>Health: {{ record.health }}

Now refresh the web page for switch01. You'll see the additional data fields on the switch01 web page now.

bolt_switch01_website_added_fields.png

Now you have your new fields on the page.

So you can see how easy it is to automate adding content to the Bolt database and presenting that data on the frontend of the website. If you get a chance to play with Bolt, I think you'll find it a very easy, yet capable CMS tool that will work well for a lot of projects.

Comments

There are no comments on this post.

Recent Posts

Archives


Contact Cecil