After one of my friends asked me about the fact that TVs are used in templates, I decided to put everything off for the evening and write this article.
It will be about what MODx consists of, how it is better to “prepare”, “serve” and “use”.
It is designed primarily for beginners because contains the basic minimum of what you need to know any modxvodu, and of course for those who are just interested.
The article is mainly focused on Revolution and reflects the main differences in its syntax from its predecessor, but for backward compatibility I will sometimes insert analogies with Evolution.
Resources
Often the resource is a website page. In addition, there are other types of resources, such as links, the files themselves, etc. By default, the type of a new resource is a document, or rather a single page representation of your site.
')
There are 4 types of resources:
- The document - the most common resource, in fact the web page of the site. In the bulk consists of the title, annotations, long text, various dates, meta tags and additional fields (TV-parameters);
- Web link - link to an external resource or web page;
- Symbolic link is an internal link to another resource;
- Static resource - file.
Each resource also has a unique identifier, or “Resource Identifier”. If you want to link two resources, then for this you should use the ID. Thus, MODx will generate a link, and you will not have to worry about changing the page address or addressing types.
You can also assign a template to each resource, the template can define additional fields of this resource.
Resources can act as containers and contain other resources. This is the structure of the site.
Templates
A template is a basic entity that determines the display of a page in MODx. Templates usually contain HTML markup tags that define the location and appearance of your site. When a site page is requested, MODx loads the document or resource and its template, then MODx finds all additional fields in the template and replaces them with the corresponding values from the document before sending the page to the user's browser.
A template can be assigned to any resource and defines the essence of a web page in which the content of this resource will be displayed.
A template cannot be included in another template as a part.
Template example:
< html > < head > < title > [[*pagetitle]] < / title > < meta name = "description" content = "[[*description]]" / > < / head > < body > < h1 > [[*longtitle]] < / h1 > ID : [[*id]] < br / > : [[*introtext]] < br / > : [[*menutitle]] < hr / > [[*content]] < / body > < / html >
< html > < head > < title > [[*pagetitle]] < / title > < meta name = "description" content = "[[*description]]" / > < / head > < body > < h1 > [[*longtitle]] < / h1 > ID : [[*id]] < br / > : [[*introtext]] < br / > : [[*menutitle]] < hr / > [[*content]] < / body > < / html >
< html > < head > < title > [[*pagetitle]] < / title > < meta name = "description" content = "[[*description]]" / > < / head > < body > < h1 > [[*longtitle]] < / h1 > ID : [[*id]] < br / > : [[*introtext]] < br / > : [[*menutitle]] < hr / > [[*content]] < / body > < / html >
< html > < head > < title > [[*pagetitle]] < / title > < meta name = "description" content = "[[*description]]" / > < / head > < body > < h1 > [[*longtitle]] < / h1 > ID : [[*id]] < br / > : [[*introtext]] < br / > : [[*menutitle]] < hr / > [[*content]] < / body > < / html >
< html > < head > < title > [[*pagetitle]] < / title > < meta name = "description" content = "[[*description]]" / > < / head > < body > < h1 > [[*longtitle]] < / h1 > ID : [[*id]] < br / > : [[*introtext]] < br / > : [[*menutitle]] < hr / > [[*content]] < / body > < / html >
< html > < head > < title > [[*pagetitle]] < / title > < meta name = "description" content = "[[*description]]" / > < / head > < body > < h1 > [[*longtitle]] < / h1 > ID : [[*id]] < br / > : [[*introtext]] < br / > : [[*menutitle]] < hr / > [[*content]] < / body > < / html >
< html > < head > < title > [[*pagetitle]] < / title > < meta name = "description" content = "[[*description]]" / > < / head > < body > < h1 > [[*longtitle]] < / h1 > ID : [[*id]] < br / > : [[*introtext]] < br / > : [[*menutitle]] < hr / > [[*content]] < / body > < / html >
< html > < head > < title > [[*pagetitle]] < / title > < meta name = "description" content = "[[*description]]" / > < / head > < body > < h1 > [[*longtitle]] < / h1 > ID : [[*id]] < br / > : [[*introtext]] < br / > : [[*menutitle]] < hr / > [[*content]] < / body > < / html >
< html > < head > < title > [[*pagetitle]] < / title > < meta name = "description" content = "[[*description]]" / > < / head > < body > < h1 > [[*longtitle]] < / h1 > ID : [[*id]] < br / > : [[*introtext]] < br / > : [[*menutitle]] < hr / > [[*content]] < / body > < / html >
< html > < head > < title > [[*pagetitle]] < / title > < meta name = "description" content = "[[*description]]" / > < / head > < body > < h1 > [[*longtitle]] < / h1 > ID : [[*id]] < br / > : [[*introtext]] < br / > : [[*menutitle]] < hr / > [[*content]] < / body > < / html >
< html > < head > < title > [[*pagetitle]] < / title > < meta name = "description" content = "[[*description]]" / > < / head > < body > < h1 > [[*longtitle]] < / h1 > ID : [[*id]] < br / > : [[*introtext]] < br / > : [[*menutitle]] < hr / > [[*content]] < / body > < / html >
< html > < head > < title > [[*pagetitle]] < / title > < meta name = "description" content = "[[*description]]" / > < / head > < body > < h1 > [[*longtitle]] < / h1 > ID : [[*id]] < br / > : [[*introtext]] < br / > : [[*menutitle]] < hr / > [[*content]] < / body > < / html >
< html > < head > < title > [[*pagetitle]] < / title > < meta name = "description" content = "[[*description]]" / > < / head > < body > < h1 > [[*longtitle]] < / h1 > ID : [[*id]] < br / > : [[*introtext]] < br / > : [[*menutitle]] < hr / > [[*content]] < / body > < / html >
< html > < head > < title > [[*pagetitle]] < / title > < meta name = "description" content = "[[*description]]" / > < / head > < body > < h1 > [[*longtitle]] < / h1 > ID : [[*id]] < br / > : [[*introtext]] < br / > : [[*menutitle]] < hr / > [[*content]] < / body > < / html >
Options
Used to display resource field values.
The call is made as follows:
Evolution | Revolution |
[* field *] | [[* field]] |
Full list of fields can be found in the documentation
here .
TV options
TV An optional field or template variable (TV) is a custom field, or more specifically, a custom field for MODx resources. TV parameters are used to expand the standard resource fields. Each resource in MODx has a certain number of fields by default. See above in the section about resources.
If the task is to add some additional fields to the page, for example, a drop-down list of month names or an additional image, or any other type of user data, this can be done by adding a TV parameter of the appropriate type. MODx allows you to have a virtually unlimited number of TV-parameters.
The TV tag is replaced with the corresponding value filled by the user when processing the resource. Also, each such parameter is tied to any template and can only be used in conjunction with it.
The call is made as follows:
Evolution | Revolution |
[* tv *] | [[* tv]] |
TV parameters can be used as chunks by adding parameters to them. For example, if there is a TV parameter 'intromsg' with the value:
- Hello [[+ name]], you have [[+ messageCount]] unread.
Then you can fill it with data when you call:
- [[* intromsg? name = `Grisha` & messageCount =` 123`]]
Result:
- Hi Grisha, you have 123 unread messages.
You can also apply filters for output, for example, so you can limit the length of the output line to 100 characters:
- [[* bioMessage: limit = `100`]]
A complete list of filters can be found
here . In addition, filters can be applied to chunks and snippets.
Comments
- [[# It is allowed to leave comments in the template, this code will be removed from the page after it is rendered. ]]
Chunks
A chunk is a piece of static text that can be embedded in a template, in another chunk, or called in a snippet. A chunk has the same properties as the template, except that it does not contain TV parameters and cannot be assigned to a resource directly.
A chunk cannot contain any executable code, but it can call snippets to display dynamic content.
The call to chunk is done like this:
Evolution | Revolution |
{{chunk}} | [[$ chunk]] |
You can pass parameters to the chunk. For example, we will create a chunk with the following content:
- Hi, [[+ name]]. You have [[+ messageCount]] unread messages.
Such a chunk can be called with parameters that will later be passed inside it:
- [[$ intro? & name = `Basil` & messageCount =` 12`]]
This code will output:
- Hi, Vasily. You have 12 unread messages.
In addition to static data, additional and general resource parameters can be placed in the call of the chunk, for example:
- [[! $ intro? & name = `[[* usersName]]` & messageCount = `[[* * messageCount]]`]]
Snippets
Snippet - PHP code that is executed during the processing of the MODx template. The result of his work can be located either at the place of his withdrawal, or in placeholders, special tags defining where to place these or other results.
The snippet call is done as follows:
Evolution | Revolution |
[[snippet]] | [[snippet]] |
Placeholder Placement:
Evolution | Revolution |
[+ placeholder +] | [[+ placeholder]] |
Like chunks, you can pass parameters to snippets, like this:
- [[! Wayfinder? & startId = `0` & level =` 1`]]
The passed parameters can be grouped into the so-called default parameters (Property Sets), which are a dynamic group of parameters that can be passed to the snippet by means of specifying the name of the group.
The default parameters are set in the administration panel on the Parameters tab of the snippet. Default parameters can also be created for chunks.
For example, create the group 'Menu' with the parameters `startId` = 0 and` level` = 1, then call the snippet like this:
- [[! Wayfinder @ Menu]]
It will be similar, because parameters will be automatically substituted:
- [[! Wayfinder & startId = `0` & level =` 1`]]
Any default parameter can be rewritten. In the following example, the value of the parameter `level` equal to one will be replaced by 2.
- [[! Wayfinder @ Menu? & level = `2`]]
To tell the system not to cache the snippet, you must add an exclamation mark in front of the name:
- [ [ ! noCacheSnippet ] ]
Tag Syntax
Each MODx Revolution tag can contain other MODx tags. In order for the code to be less readable, it is allowed to place the tag code on several lines adhering to this general format (in brackets my comments, which are not necessary to write =)):
- [[(opening tag)
- ! (optional, prohibit caching symbol)
- elementToken (optional, character specifies the type of the parameter, if it is not a snippet, $ = chunk, * = normal / additional resource field, + = placeholder, etc.)
- elementName (element name)
- @propertyset (optional, PropertySet identifier)
- : filterName = `modifier`: ... (optional filters, one or more)
- ? (optional, defines the beginning of the line with parameters)
- & propertyName = `propertyValue` & ... (optional, any parameters separated by &)
- ]] (closing tag)
MODx tag syntax summary
Element | Evolution | Revolution | Example |
TV setting | [* templatevar *] | [[* templatevar]] | [[* pagetitle]] |
Chunk | {{chunk}} | [[$ chunk]] | [[$ header]] |
Snippet (a piece of php code) | [[snippet]] | [[snippet]] or [[! snippet]] | [[getResources]] |
Placeholder | [+ placeholder +] | [[+ placeholder]] | [[+ modx.user.id]] |
Link to resource | [~ link ~] | [[~ link]] | [[~ 13]] |
System settings | [(system_setting)] | [[++ system_setting]] | [[++ site_start]] |
Resources