Content Templates
You can structure your website’s content into pre-defined sets of blocks so content authors can edit content without knowing advanced HTML concepts.
Instead of only providing you with a single rich text editor per page, Live Editor gives you the opportunity to break each page down into several blocks of content.
These blocks of content can be simple elements like text, images, videos, audio, and files. Or you can create your own content templates to mix and match these elements together as one unit.
Live Editor ships with a set of base content templates based on the individual content elements available:
- Audio
- Date
- File
- Image
- Link
- Text
- Video
You can also create your own custom content templates to mix and match one or more of these different elements.
Base content templates
When you open a new Live Editor account, your new site will come with a set of base content templates. It’s possible that you could create an entire website based on these base content templates, and that may be all that you need.
Following is the list of base content templates.
Text content templates
- Text
-
Live Editor’s rich text editor allows content authors to create blocks of text and format them with WYSIWYG tools.
Based on the
text
block object.
Date content templates
- Date
-
Date and time can be recorded and formatted in a myriad of different ways.
Based on the
date
block object.
Media content templates
- Image
-
Allows content authors to upload, format, and reference standalone images.
Based on the
image
block object. - Video
-
Allows content authors to upload and embed videos. Also includes the ability to reference videos uploaded to YouTube and Vimeo.
Based on the
video
block object. - Audio
-
Allows content authors to upload and embed audio files.
Based on the
audio
block object. - File
-
Allows content authors to upload and embed and/or link to files for download.
Based on the
file
block object.
Custom content templates
Custom content templates allow you to group together any of the base content elements and define how it all should be displayed in different scenarios.
Consider an About Us page that lists your company’s key staff members. You’ll typically want to list the same type of information for each staff member (name, photo, job title, department, short bio, etc.), and you’ll typically want for the HTML to be the same for each staff member’s listing.
Rather than training content authors on how to structure the HTML for each listing and teaching them how to edit each photo to fit within a certain set of dimensions, you can create a custom content template that asks for the data and then formats it within pre-defined HTML markup for them automatically.
What’s more, you can use displays to provide content authors with options on how they want to display each piece of content in different scenarios. For example, perhaps you only want to show the staff member’s name, job title, and a thumbnail of their headshot on a listing page, but then you want to link it to a full bio that lists the rest of the information.
This is entirely possible with custom content templates, and the content author will only need to maintain one content item to update multiple pages.
Generating a new custom content template
Using
Live Editor CLI, run the
liveeditor generate content_template
command to generate a new content template with
the data that we need:
This command will generate the skeleton of a new content template titled “Staff” with 5 blocks:
You could also run the command without all of the blocks if you want to define those later:
If you look at your theme’s folder structure, you’ll see some new files and folders:
- ...
-
content_templates
-
staff
- default_display.liquid
- content_templates.json
-
staff
- ...
In most cases, this skeleton is just a start for configuring the content template. Read on for more details about the available options.
Content template theme file and directory structure
Within the content_templates
folder of your theme are 2 types of files.
content_templates.json
config file
Within the root content_templates
folder is a
JSON config file named
content_templates.json
.
This file allows you to configure your theme’s content templates, their blocks, and displays.
Here is a sample content_templates.json
file containing our example staff
content template, its blocks, and its displays:
As you can see, there are 3 types of data represented here: (1) a top-level content template with a (2) collection of blocks and a (3) collection of displays.
Content template config options
A content template can be configured with these options:
Option | Required | Description |
---|---|---|
title
|
Yes |
string Title of content template as it will appear in the admin interface.
|
var_name
|
No |
string This will be used to reference this content template within
layout region definitions (for example, you can configure a region to only allow certain
content templates, and you would use this var_name to identify that). If not
provided, var_name defaults to the value of title , all lowercase
and underscored (for example, if the title is “Blog Post,” the default value for
var_name will be blog_post ).
|
description
|
No |
string Brief description of content template. Will appear in hints for content
authors in the admin interface.
|
icon_title
|
No |
string Title of icon to use to represent this content template in the content
editing interface. This should reference the title of an icon in the
Font Awesome icon library (sans the fa-
part of the CSS class name). If no value is
provided a default value of
edit will be used.
|
unique
|
No |
boolean Set this to true if the content template can only be
used once on any given page.
|
folder_name
|
No |
string Overrides the name of the folder within content_templates
that will contain .liquid template files for this content template. If not
provided, defaults to the value of var_name .
|
blocks
|
No |
array Collection of data that content based on this content template should
record. See Block config options section below for more
details.
|
displays
|
Yes |
array Collection of .liquid templates that are available as options
for displaying this content within different pages. See
Display config options section below for more details.
|
Block config options
A block listing within the blocks
array can contain these options:
Option | Required | Description |
---|---|---|
title
|
Yes |
string Title of block as it will be displayed to content authors in the admin
interface.
|
data_type
|
Yes |
string Type of data that the block will record. Valid values are
text , date , image , video , audio ,
file , and link .
|
description
|
No |
string Brief description that will appear as hints for this field for content
authors in the editor interface.
|
required
|
No |
boolean Whether or not the field is required. Defaults to false .
|
inline
|
No |
boolean If the data_type is set to text , passing
true for this option specifies that the text is not to be wrapped in any
block-level elements like <div> or <p> tags. This
allows you to be able to mark up this text within predefined block-level elements in your
display templates, but with the ability for content authors to still use inline-formatting
tags like <strong> and <em> .
|
var_name
|
No |
Variable name that will represent this block within the content template’s associated
.liquid display templates. Defaults to the value of title ,
lowercased and underscore-delimited (e.g., a block titled “Download Type” would
default the var_name to download_type ).
|
Display config options
A display listing within the displays
array can contain these options:
Title | Required | Description |
---|---|---|
title
|
Yes |
string Title of this display as it will appear for content authors in the admin
interface.
|
description
|
No |
string Brief description of display that will appear for content authors in the
admin interface.
|
default
|
No |
boolean Whether or not this display should be considered the default for the
content template. Only one display within each content template may have this value.
|
file_name
|
No |
string Overrides the name of the .liquid file that contains Liquid
markup for this display.If not provided, this defaults to the value of title , lowercased, underscored,
and postfixed with _display (e.g., a display titled “Event Calendar”
will refer to the file named event_calendar_display.liquid ).The file_name must contain a .liquid extension.
|
Marking up displays using Liquid
Now that you have the content template configured using content_templates.json
, you
can write the front end code using Liquid markup.
When creating content templates, there will be a subfolder within the
content_templates
folder for each content template. Within these subfolders, you store
.liquid
files for defining how data within the content editor and final website should
be displayed.
With our example “Staff” content template, there should be a folder at
content_templates/staff
that contains these Liquid templates. We will be working
with a couple displays:
- Default will represent a full staff record and will appear on its own page.
- List will represent part of the staff record, intended to be displayed on a list page with multiple staff members, with links to separate pages for each staff member.
So our folder tree should look like this:
- ...
-
content_templates
-
staff
- default_display.liquid
- list_display.liquid
- content_templates.json
-
staff
- ...
When working with these files, we can use all that Live Editor has to offer with its implementation of Liquid.
Also, we have access to each block represented for the content template in
content_templates.json
. Using our example content_templates.json
file, we have these variables at our disposal within each .liquid
file:
-
full_name
-
hire_date
-
photo
-
job_title
-
department
-
bio
-
full_bio_link
Using that, we can code up a list_display.liquid
template fairly easily, using Liquid
markup however we want:
The same goes for default_display.liquid
:
The main point of showing these 2 examples is to demonstrate that you can include as little or as much data from the content template into each display, and you can mark up each display differently if needed.
For more information about using the Liquid templating language in Live Editor, refer to the Liquid Reference.
Next steps
Learn some helpful rules of thumb for authoring your code so that it works well with Live Editor’s flagship Inline Editor feature in the Designing for the Inline Editor guide.
Or learn everything that you need to know about Live Editor’s implementation of Liquid in the Liquid Reference.