Learning Modx, Tutorial #1 Creating a Template
June 26, 2010 24 Comments
This Tutorial will walk you through the steps to create a simple template for Modx CMS.
Audience, who is this tutorial for?
This tutorial is aimed at those that are new to Modx Revolution, but also have a good understanding of HTML and CSS. This tutorial will not cover how to create HTML or CSS.
Version
Modx Revolution 2.0.0 rc2 and above.
Requirements
You should have a working version of Modx Revolution so you can follow along.
Download Code files – updated 9-26-2011 I moved this Tutorial and code.
Make sure that you have the following packages installed before you begin this tutorial
- getResourcesPackage Page: http://modxcms.com/extras/package/552Docs: http://svn.modxcms.com/docs/display/ADDON/getResources
- Wayfinder
Package Page: http://modxcms.com/extras/package/487Docs: http://svn.modxcms.com/docs/display/ADDON/Wayfinder
Optional Packages
These optional packages are not required to complete this tutorial, but you may find them helpful.
Concepts/terms used
- Templates
- Tags
- Template Variables
- Chunks
- Dynamic menu/navigation creation
- Categories
The Tutorial, version 1.0
-
Create a Category
The first thing we want to do is create a category. This will help us keep all of our pieces easily organized. As you create more templates, chunks, snippets and plugins this becomes very important.
- Click on the Elements tab
- Right click on Categories, you will see New Category appear, left click on it.
- For the Name field type in: Webdeveloper
Note the Parent field allows you to have nested or sub categories.
-
Create Template Variables
Okay now I want to create TVs(template variables). You probably are saying what is that? So here is the simple scenario. In our template we want to allow customization on every page/resource some additional text fields like meta info, CSS and JS. Don’t get confused here, we are planning to use a global CSS file and JS files, but these will allow us to have properly embedded CSS and unobtrusive javascript for each page we create!.
NOTE: you cannot have HTML tags in the name, description, etc when you are creating the TV!
- Again in the Elements tab, right click on Template Variables and click on New Template Variable.
- We are only going to use the General Information tab. We will fill in the Variable Name, Caption, Description, Category (Webdeveloper), Input Type and for one TV Default Value. Only enter/change the values listed, see the list below of the TVs you should create.
- More info on Creating TVs
TVs to create:
- Variable Name: meta-keywords
Caption: SEO Keywords
Description: 5 to 7 keywords related to this page.
Category: Webdeveloper
Input Type: Text - Variable Name: meta-description
Caption: SEO Description
Description: A 25 words or less description related to this page.
Category: Webdeveloper
Input Type: Textarea (mini)
Default Value: [[*introtext]] - Variable Name: webdeveloper-css
Caption: Embedded CSS
Description: Enter in your CSS, remember to wrap in style tags
Category: Webdeveloper
Input Type: Textarea - Variable Name: webdeveloper-js
Caption: JavaScript
Description: Enter in your JS, remember to wrap in script tags
Category: Webdeveloper
Input Type: Textarea
-
Create the Template
Now that we have created some TVs lets create a Template. We want to make a template that will be flexible by allowing us to create more templates using some common elements like banner, navigation menu and footer. Once you get an understanding of this you will see how to make sub templates and many more options.
- Again under the Elements tab right click on Templates and then left click on New Template
- Fill in the Template name: WebdevelopmentTemplate1
- Description: Our first Template!
- Select the category: Webdeveloper
- Paste in the HTML code from the WebdevelopmentTemplate1.html file
- Now click on the Template Variables tab and check all of the ones we created in step 2
About the “[[”, this is the start of a Tag. I used two types in our template, the first type you see is [[*, this is for the TVs that we created. Our template will now import the value of those TVs for each page/resource. The [[$ is for Chunks. Chunks are simply little bits of HTML. Now we need to create the banner, navigation and footer Chunks.
-
Create the Chunks
- Under the Elements tab, right click on Chunks and then left click on New Chunk.
- Fill in the Name: webdeveloper-banner
- Description: HTML Banner
- Category: Webdeveloper
- Chunk code (html): Paste in the HTML code from the webdeveloper-banner.html file
Now do the same and create these two chunks:
- Name: webdeveloper-navigation
Description: This is the main navigation HTML
Category: Webdeveloper
Chunk code (html): Paste in the HTML code from the webdeveloper-navigation.html file - Name: webdeveloper-footer
Description: This is the footer HTML
Category: Webdeveloper
Chunk code (html): Paste in the HTML code from the webdeveloper-footer.html file
-
The CSS file
Now the last piece in our example, the CSS file. We need to have the CSS file uploaded to:
(the folder where you have modx)assets/templates/webdeveloper/css/layout.css. You can do this two ways, via FTP or the File manager.Using the File Manager:
- Click on the Files Tab
- Navigatigate to assets/templates – note if these folder/directory are not here you will have to create them.
- Create the Directory webdeveloper by right clicking on the folder templates. Then left click on Create Directory Here.
- Do the same with css
- Now right click on the css folder/directory and left click Upload Files
- Click the add button and select the layout.css file
- Click the Upload button then Close.
-
Create a test page
- Click on the Resources tab
- Right click on web and hover over Create and then click on Create a Document Here
- Now select the Template WebdevelopmentTemplate1 and an alert message will pop up, click Yes.
- You can name the file whatever you would like.
- Now click on the Template Variables tab, and you will see the text fields we created!
- Open up the file testpage-data.txt and copy and paste into the appropriate fields
- Now save and preview and you should see your page!







Pingback: Tweets that mention Learning Modx, Tutorial #1 Creating a Template « Web Development -- Topsy.com
I try to follow the tut, but where is the WebdevelopmentTemplate1.html file? it’s not in the webdev-files.zip.
Sorry I forgot a file, here is the new link with all files: http://modxcms.com/forums/index.php?action=dlattach;topic=50951.0;attach=12524
Sometimes it’s really that simple, isn’t it? I feel a little stupid for not thinking of this by myself.
Great post!
Very quick and simple tutorial. Thanks. Please post more in the future.
that was the most useful modx post I have come across, Thanks.
Good job. Thank you for this quick intro to Revolution. This the best I had found.
I followed the tutorial and successfully created a page. Fantastic. I previewed it and the browser showed the URL as:
http://localhost/modx2/index.php?id=2
Good to have many pages created, this is a good start. Next I got to learn about navigation and learn how to connect/link them all up. Hope you will be doing more of this kind of useful tutorial for a complete Modx dummy like me.
Regards
kc
Thank you for your clear, concise tutorial.
thanks for admin wonderfull information…
Excellent!
Best tutorial on the net for MODx Revolution so far. We need more like this. Thanks!!!
You just cleared up a mess of questions with this tutorial….thanks !!!
Great first tutorial for starting out with MODx! Worked first time too
Whet my appetite for finally diving into MODx.
I cannot get past making a chunk. When i copy and paste
[[++site_name]]
it won’t and my browser says there is an error on page. If I remove the
then it saves… but it refuses to save with in the chunk code
stuck.. and p*ssed off
What browser are you using? I suggest FireFox. What version of MODX Revolution are you using?
Shane, probably you were pasting the code as shown when opening the banner.html file in a browser. You need to right click the file and open in a text editor to get the full code as:
[[++site_name]]
Oh Oh. that didn’t work coz the HTML tags have been stripped out when i posted the comment. The entire code should be enclosed in a div tag with id=”banner”, and the sitename placeholder is enclosed within h1 tags (within the div). Hope you know what i mean.
Haven’t followed it completely yet.(My pizza needed to be taken out of the oven) Just wanted to say thanks as it’s exactly what I was trying to figure out. And, honestly documentation was to broken up on the step by step. Just explained the parts and not where to start
.
It was a clear and simple way to guide through the first steps of setting up your template. I already had my Main page’s HTML ready but I could adopt it following your guidelines and it works without a hitch. Thank you.
so, how does one create the promised “sub templates”? thanks!
the Code files don’t exixst
I moved them to here: http://www.joshua19media.com/modxtutorials/creating-a-modx-revolution-template.html
you can say me the link where is the Code files?
Isn’t possible to create the css in the “Ressources” and link it in the template with [[~ ? So that it’s possible to update it online..