Understanding Article Templates in MODX

Beginning Articles users are often confused (as I was) by the two main Templates used to style your Articles blog. Articles comes with two sample Templates to use as models. They’re both shown on the Elements tab under “Templates -> Articles”.

The sample.ArticlesContainerTemplate, is the Template for the blog’s Home page — the one that shows the list of recent articles.

The sample.ArticleTemplate is the Template used when users look at a single blog post.

Don’t Modify the samples!

As you probably know, it’s a bad practice to modify any Templates or Tpl chunks that are installed as part of an extra because when you upgrade the extra, all your work will be overwritten and lost. It’s also nice to have the originals to refer to in case things go bad. Instead, you should duplicate them. My practice is to change the names of everything I duplicate by taking out the word “sample” (or anything similar) and adding a “My” prefix. That way, I always know which elements are my own because they’re all prefixed with “My”.

Duplicate the two Templates by right-clicking on them in the tree and selecting “Duplicate Template” on the context menu. Change the names to “MyArticlesContainerTemplate” and “MyArticleTemplate”, then click on the “Save” button. Your own Templates should now appear in the Elements tree under Templates -> Articles.

Setting the Templates

Even after you’ve duplicated them, Articles will still use the two default Templates until you change them. To activate your Templates, right-click on the Blog container in the Resources tree and select “Manage Articles”, then click on the
“Template” tab (second from the left).

At the top of the Template tab, you’ll see two drop-down selectors. The left one (“Uses Template”) sets the Template of the blog Home page. The right one (“Article Template”) sets the Template for individual blog posts. Set the left one to “MyArticlesContainerTemplate” and the right one to “MyArticleTemplate” then click on the “Save” button at the upper right. Your Templates should now be set. You can now edit your own Templates and the changes should show up in your blog.

Edit them as you would any Template by right-clicking on them in the Elements tree and selecting “Edit Template.”

If you’ve been using your own Templates for a while and want to make major changes to them, it’s not a bad idea to duplicate your own Templates first to back them up in case things go wrong.

A Note About Changing Templates

If at some point, you want to change to other Templates altogether, changing the ArticlesContainer Template will take effect immediately, but changing the Article Template will not affect existing blog articles. The Article Template setting basically just overrides the default_template System Setting. It only affects new articles. To change the Templates of existing articles, you need to edit each one and set its Template using the drop-down list on the right side of the Create/Edit Article panel, then save it.

This sounds like a pain, but it allows you to use different Templates for different kinds of blog posts. If you need to change a bunch of Article Templates, use the Batcher extra. On the “Resources” tab, you can select the articles using the “Filter by Template” drop-down at the upper right, then check the ones you want to change and use the “Bulk Actions” drop-down at the upper left to change the Template of the selected articles.

For more information on how to use MODX to create a web site, see my web site Bob’s Guides, or better yet, buy my book: MODX: The Official Guide.

Looking for quality MODX Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , | Posted under MODX | RSS 2.0

Author Spotlight

Bob Ray

Bob Ray is the author of MODX: The Official Guide and over 30 MODX add-on components. He hosts Bob's Guides, a source of valuable information for MODX users, and has been very active in the MODX Forums with over 19,000 posts.

One Comment on Understanding Article Templates in MODX

  1. Claudette says:

    This is my first time visit at here and i am actually happy to read all at one place.

Leave a Reply to Claudette Cancel reply

Your email address will not be published. Required fields are marked *