Templates
A template is the HTML for a kind of page, such as a blog post, a product page, or a location page. Once a site has one, anyone with access to the site can add a page by selecting New Page, picking a template, and giving the page a name. Surreal CMS writes the file to your server, enables it, and opens it in the editor. Clients can add their own pages, and you never have to upload a file first.
Every page made from a template starts with the same header, footer, styles, and content regions, so new pages match the rest of the site and are ready to edit right away. Without a template, New Page explains what's missing. Only administrators can add templates.
Creating a template
Open the site, select Templates in the sidebar, then select New Template. Each site can have up to 100 templates.
| Name | What people pick from the list, such as “Blog post” or “Location”. |
|---|---|
| Description | A line about what the template is for. |
| File Extension |
The extension new pages get, such as .html or .php. It must be one Surreal
CMS can edit.
|
| Source | The full HTML source of the page. Paste it in or drop an HTML file. |
The easiest way to make a template is to take a page that already works in Surreal CMS and paste in its
source. Everything in it becomes the starting point: the <head>, the header and footer,
the content regions, and whatever content is in them. A few things make
a template better to work from.
- Put placeholder content in each region that says what goes there, such as a heading that reads “Post title” and a paragraph that reads “Write the post here.” Editors replace it.
-
Use root-relative URLs, such as
/assets/site.css, for stylesheets, scripts, and links. A new page can be created in any folder, and relative paths break when it isn't next to the template's original. - Leave the title and description generic. Editors set them per page with Edit Metadata.
-
Give each region a unique
id, just like on any other page. Ids in the template are fine because each page is its own file.
If the template has static includes, they stay current. When you publish a page with a static include, the matching include in each template is updated too, so new pages always start with the latest header and footer.
Adding a page
Open the site and select New Page. Choose a template and enter a name for the page. Surreal CMS suggests a filename from the name, which you can change, and the extension comes from the template. Choose a folder if the page shouldn't live at the site's root. The page will be created inside that folder on your server.
Surreal CMS creates the file, enables it, and opens it in the editor. It never overwrites a file, so if one already exists at that path you'll get an error instead. The person who added the page can edit it right away. Clients who are limited to certain pages won't see it until an admin adds it to their permissions.
Duplicating a page
The other way to make a page is to copy one that exists. An admin turns this on per site with Duplicate pages under Edit Site. After that, Duplicate appears in each page's menu. A duplicate starts with the page's current source, content and all, which is handy when the new page should look like an existing one, such as a second location. Templates are the better choice when every new page should start clean.
Templates are copies
A new page starts with a copy of the template's source. Editing the template afterwards changes the pages you create from then on, but existing pages keep the source they were created with. For anything that has to stay the same on every page, use includes.