Описание тега modx-templates

Questions about creating, managing and using templates and their variables in the ModX CMP. Templates in ModX are a way to manage look at functionality between types of ModX Resources.

Templates in ModX (Evolution and Revolution) are ModX Elements allowing management of style and functionality by type of ModX Resources. A simple example is: Assume you have a Resource that is an article. The content of the document is the Resource itself. The template would be article.

This structure allows the developer to logically design groups of resources at once. Modx Markup can then be utilized just as simply in the template rather than the resource. With ModX Chunks and Snippets, the structure is pretty free form. This allows for many different levels of abstraction, depending on need.

Template Variables

Templates have the ability to apply variables to Resources that use them. These variables may be a variety of different types, displayed in a variety of different ways. Each may also have validation included by the system or even custom validation. Every resource that uses the template may then have its own value for that variable. Validation occurs at the time the resources is edited.


Creating a Template

While there are many plugins for managing resources and their content through the front-end of your website, Templates should be created and edited through the manager. For more detail, see the ModX Documentation for Templates

  1. Log into the Manager.

  2. In the sidebar, click on the "Elements" tab.

  3. Either: a) Right click on Templates and choose "Create Template"; or b) Click on the button that looks similar to a form or window (a tooltip will appear showing "New Template").

  4. Add a name.

  5. Add some content that you want to see in all documents of that type. Don't forget to place [[*content]] where you would like it to be rendered.

  6. Click "Save".

Creating a Template Variable

These instructions explain how to make the most basic template variable. Template Variables have so many options, it is impossible to completely cover them here. A more detailed resource can be found in the ModX Documentation for Template Variables

  1. Log into the Manager.

  2. In the sidebar, click on the "Elements" tab.

  3. Either: a) Click on the button that looks like a TV; or b) Right click on Template Variables and choose "Create Template Variable".

  4. Add a name: this can be referenced in markup using [[*name]].

  5. Add a caption: this is the display name on the resource editing form.

  6. Click on the "Input Options" tab. Choose the type of variable.

  7. Click on the "Template Access" tab. Click the check box next to each template that you want add the variable to.

  8. Click "Save".