MODX developer info

Implementing MODX templates from html and CSS

The main resource for MODX documentation is their online manual.

MODX Manager

Resource, Elements and Files tabs

Resources: which are database-generated pages or links, arranged as nodes in a tree structure
They can include CSS pages if this is wished
They include some basic template variable fields, including longtitle and content
RTFM page
Elements: which are back-end things
RTFM page
Templates: which structure the page
RTFM page
Template Variables: custom information assigned to resource / page
Call a TV in a template with [[*tvname]]
Chunks: chunks of recyclable html, can contain database information ‘placeholders’,
Chunks can also ‘nest’ more chunks, plug-ins, etc
Call a chunk in a template with [[$chunkname]]
RTFM page
Snippets: small pieces of php code
run a snippet in a template with [[snippetname]]
run a snippet each time the page is loaded with [[!snippetname]]
Nearly all snippets use a ‘chunk’ to render their output,
to make sure style and content are separate
Snippet database results are normally placed into hunks with [[+placeholders]]
RTFM page
Plug-ins: bigger programmes
They execute as the page is generated or form other system events.
Plug-ins are not therefore placed into a Template, as they are more functional
RTFM page
Files: arranged as the end user wishes, including images, CSS files, documents

Building a template

  • Place the page structure into the Template
  • Add common fields like [[*content]] and [[*longtitle]]
  • Add any custom TV output
  • Render internal links by pointing to the node number, like this <a href="[[~123]]”>
  • Where several similar templates use the same html, these can be placed in [[$chunks]] to make updating easier

So you might have


<body> 
[[$standard_head]] 
[[$template_content]] 
[[$standard_footer]] 

</body>

or

<body> 
<h1>[[*longtitle]] </h1> 
[[*content]] 
<p>Copyright notice and privacy policy</p> 
</body> 

Building menus and database content with snippets

  • Wayfinder is used for menus
  • Getresources are the main ways to generate database content
  • Quip is used for comments
  • Archivist is used for lists of posts
  • Taglister is used to generate tag lists
  • If is used to create conditional statements within templates (if this do that)
  • Articles is used to standardise the use of these for blog posts

Each ‘snippet’ has a database call which looks like this:

[[snippetname? option=`one` otheroption=`2` templatechunkforrenderingoutput=`chunkname` ]] 

Blogs posts using Articles

Articles standardises all this, and requires us to use two templates, one for the blog listings, and one for the blog posts

Two sample templates can be adapted, Prism articles and Prism articles list