Introducing Snippets

Posted in Announcements on Feb 13, 2015

The Static Pages plugin is an important part of the OctoberCMS world. If you haven't heard about the plugin please read the Getting started with Static Pages and Static pages - content blocks and placeholders posts. Recently we added another powerful feature to the plugin - called Snippets.

The purpose of the Static Pages plugin is to allow non-technical users to manage website content so that they can easily create and edit static pages, menus, and content blocks. Sometimes static content is not enough, this is where Snippets comes in! Simplifying the process, it allows users to add dynamic elements to static pages.

Some of many uses for Snippets:

  • A contact form - might be needed on the About page. If a company has multiple locations, the editors might want to add a separate form on each page describing a location.
  • Google maps - might be needed on pages describing tourist attractions.
  • Photo gallery - users might want to add this snippet to pages describing recent events.
  • Registration forms - could be useful on pages describing future events.
  • Voting forms - would be helpful on survey pages.
  • Universal commenting system - would work on any static page where comments are wanted.
  • Third-party integrations - for example with Yelp or TripAdvisor for displaying extra information about a business or location.

Two ways to create snippets

The first way is to convert a CMS partial to a snippet. It's a simple and powerful option - if you have access to the CMS area then you can create snippets. No PHP coding is required (although it's supported on the partials Code tab). To make a snippet from a partial just type the snippet name and code on the Edit Partial form. Partials can contain any Twig content and that makes them dynamic. You can even define snippet properties right in the CMS area. The properties can be accessed in the partial code as normal Twig variables. End users can set property values when they add snippets to a static page.

http://i61.tinypic.com/2juurl.png

For example, the Google Maps snippet could be defined as a partial as its markup is quite simple and doesn't require any complex programming.

http://i60.tinypic.com/15citzp.png

The limitation of snippets created from partials is that they can't handle AJAX and form events. If you need the full power of October front-end framework, you should create snippets from components instead. Basically, any component can be registered as a snippet. Please refer to the plugin documentation to see how to do it. There is no technical difference between components running on a CMS page and a snippet running on a static page, so when you build a CMS component you get a snippet for free!

As you can see, Snippets are a fantastic addition to the Pages plugin and there are even more treasures planned! The next big feature we're going to build is the Media Manager which will let your customers manage images and other files.

See also

  • See Static Pages plugin technical documentation for more information about creating and using snippets.
comments powered by Disqus