Couch CMS and the lazy developer
Tags: cms, webdev
Published: 2017-09-21 00:01:35

---
title: Couch CMS and the lazy developer
published: true
description: A CMS to make static sites a little dynamic and lazy developers a little happy. Also, guys, look I didn't write a security thing.
tags: #cms, #webdev
cover_image: https://thepracticaldev.s3.amazonaws.com/i/hqnawqj48rdgt6jpxsyx.png
---

I do not claim to be a developer, not a good one at least. In fact, I think it would almost insult other developers to call myself one. My only in-depth development experience, aside from writing some smaller tools for work, is as web developer for a start up in college. I worked with Wordpress (written in PHP) and later with Magento and coding with Liquid. I was okay with it but it taught me how tedious working with a CMS can be. Now, I run Reboot Iowa, a non-profit I founded to teach basic computer programming concepts and encourage technical literacy. We designed and built our own website and it looks great (with the exception of a few edits that need to happen on the Donate page, hey...I'm honest about it). The downside is that it is completely static which is not helpful for loading information about upcoming workshops and events dynamically. It's also a pain to update anything, which happens pretty often when you're a budding organization of any kind. 

##Enter Couch CMS

I spent a few days Googling some solutions for a lightweight CMS. I really didn't want to have to write a Wordpress theme or start all over with a new website while integrating a CMS. And it isn't because I don't think I can do it, but I'm pretty lazy. As I said before, I don't consider myself a developer and so it takes me longer than necessary to figure out everything and I just don't want to spend the time. Enter Couch CMS, a CMS for lazy people like me. Easy to set up and use and even comes with an admin panel. Prayers answered. Now, don't get me wrong. I can see how this tool would be totally useful for non-technical people with a need and being non-technical doesn't make them lazy. I'm calling myself lazy because I have the technical skill and knowledge to master a more robust CMS or even use a framework to build my own and simply choose not to. 

I used MAMP to set up a local dev environment on my laptop to test out Couch. Couch CMS is written in PHP, a requirement I had for any solution I ended up using because it's the web language I'm most comfortable with. PHP was the first web language I learned, so it's close to second nature now. 

I really liked that I could easily plug in dynamics pieces to a static site. All I had to do was require a file from the Couch directory (couch.php) and invoke at the end of the file. I eventually used it to easily update the bios for myself and my board members and to update various fields such as our 'About Us', 'Vision and Mission', and various other texts that might change in the future. My favorite part was being able to have upcoming events appear on the site and disappear after the date of the event passed. Now Couch is running on our production [Reboot Iowa website](rebootiowa.org) and it's working out well so far. I still need to add in the necessary code to make our Announcements and News dynamic, but..well... I'm lazy remember?

## A Little Taste
Here's a sample of how I added a dynamic events section to the homepage of Reboot Iowa's website.

I began by defining a template for an event in a file called events.php. With this template, an event object appears in the admin panel. 

```
// events.php
<?php require_once( 'couch/cms.php' ); ?> 
<cms:template title='Event' clonable='1' > 
	<cms:editable name='event_description' type='richtext' />
	<cms:editable name='event_image'
		crop='1'
		width='610'
		height='150'
		type='image'
	/>
	<cms:editable name='location' label='Location' type='text' />
	<cms:editable name="event_link" label='Event Sign Up Link' type='text'/>

    <cms:editable name="start_time" label="Time From (24 Hrs)"
      opt_values=' Unspecified |
                  00:00 | 00:30 | 01:00 | 01:30 | 02:00 | 02:30 | 03:00 | 03:30 |
                  04:00 | 04:30 | 05:00 | 05:30 | 06:00 | 06:30 | 07:00 | 07:30 |
                  08:00 | 08:30 | 09:00 | 09:30 | 10:00 | 10:30 | 11:00 | 11:30 |
                  12:00 | 12:30 | 13:00 | 13:30 | 14:00 | 14:30 | 15:00 | 15:30 |
                  16:00 | 16:30 | 17:00 | 17:30 | 18:00 | 18:30 | 19:00 | 19:30 |
                  20:00 | 20:30 | 21:00 | 21:30 | 22:00 | 22:30 | 23:00 | 23:30 |'
      type='dropdown'
    />

    <cms:editable name="end_time" label="Time Until (24 Hrs)"
      opt_values=' Unspecified |
                  00:00 | 00:30 | 01:00 | 01:30 | 02:00 | 02:30 | 03:00 | 03:30 |
                  04:00 | 04:30 | 05:00 | 05:30 | 06:00 | 06:30 | 07:00 | 07:30 |
                  08:00 | 08:30 | 09:00 | 09:30 | 10:00 | 10:30 | 11:00 | 11:30 |
                  12:00 | 12:30 | 13:00 | 13:30 | 14:00 | 14:30 | 15:00 | 15:30 |
                  16:00 | 16:30 | 17:00 | 17:30 | 18:00 | 18:30 | 19:00 | 19:30 |
                  20:00 | 20:30 | 21:00 | 21:30 | 22:00 | 22:30 | 23:00 | 23:30 |'
      type='dropdown'
    />

    <cms:editable name='end_date'
        label='Event End Date (if multi-days event)'
        desc='Enter date in yyyy-mm-dd format e.g. 2010-12-31'
        type='text'
        validator='regex=/(?:19|20)\d\d-(?:0[1-9]|1[012])-(?:0[1-9]|[12][0-9]|3[01])/'
        separator='#'
        validator_msg='regex=Incorrect date format'
    />
</cms:template>
<?php $title="Event"; include('header.php'); ?>
<div class="row" >
    <div class="col-sm-12" style="margin-top:35px;">
        <h2 style="margin-left:10px;">Upcoming Events</h2>
        <div class="row">
          
        </div><hr>
        <div class="row">
           
        </div>
    </div>
</div>
<?php include('footer.php'); ?>
<?php COUCH::invoke(); ?>
```

After creating the template and creating some events, I added the necessarily code to the index file to display information about upcoming events. 

```
// index.php
...
...
...
<h2 style="margin-left:10px;">Announcements and Upcoming Events</h2>
        <div class="row">
            <div class="col-sm-3">
                <p class="lead section-lead"><i class="fa fa-calendar fa-2x" aria-hidden="true" style="padding:10px;"></i> <strong>Events </strong></p>
            </div>
            <div class="col-sm-9">
                <cms:set today="<cms:date format='Y-m-d' />" />
                <cms:pages masterpage='events.php' orderyby='end_date' order='asc'>
                <cms:if today lt end_date>
                  <p class="lead section-lead" style="/*margin-left:10px;*/"><cms:show k_page_title /> | <cms:date end_date format='F j' /> </p>

                  <p style="margin-left:10px;">
                    <cms:show event_description />

                      Time: <cms:date start_time format='g a' />-<cms:date end_time format='g a'/></br>
                      Location: <cms:show location />
                      <cms:if event_link !='Unspecified'>
                        <br><a target="_blank" href="<cms:show event_link />">Sign up Here</a>
                      </cms:if>
                  </p>
                </cms:if>
                </cms:pages>
            </div>
...
...
...
```

You'll notice I set a variable `today`, done by using the `cms:set` tag, to compare the event date with the current date in order to determine which events to show. 
```
                <cms:set today="<cms:date format='Y-m-d' />" />
                <cms:pages masterpage='events.php' orderyby='end_date' order='asc'>
                <cms:if today lt end_date>
```

The many tags, such as `cms:set` and `cms:if`, allow me a small range of flexibility when working with the Couch to display information that I really appreciate. 

Setup documentation can be found [here](http://docs.couchcms.com/tutorials/portfolio-site/building-a-real-world-site.html). In short, all you do is unzip a folder and place it in a directory. After updating the config file with the credentials for your SQL database, you navigate to the admin panel, complete installation, and you're good to go. I won't get into all of the details, but if you'd like to know more about CouchCMS, they have really good [documentation](http://docs.couchcms.com/). I used to documentation as a guide to figure out everything I needed. 

I'm more curious to know about other lightweight CMS's you guys have heard about or tricks you've picked up when running a dynamic site to make it a little easier to use. If you end up trying out Couch, let me know what your think.