MODx From the Inside: Using TV Bindings | Использование @-команд в параметрах TV History of edits
(Latest: gorbarov 1 year, 5 months ago)
§ | |
| Использование @-команд в параметрах TV History of edits
(Latest: gorbarov 1 year, 5 months ago)
§ | |
Bindings allow a TV to get its content from an external source. This could be the output of specified PHP code, a file, another document or from the database. Bindings are specified by using the @BINDING syntax in the TV's Default Value field. | | |
Bindings are used simply by entering the binding you want to use, followed by the file name, chunk name, document ID, PHP code to be parsed, sql query to be executed, etc. | | |
The code for processing bindings is in the /manager/includes/tmplvars.commands.inc.php file. | | |
There are seven binding options. | | |
@FILE - use the contents of the given file. A full or relative path to the file must be used. | | |
@CHUNK - use the content of the given chunk, using the chunk's name. | | |
@DOCUMENT - use the content of the given document, using the document's ID (the number in parentheses to the right of the document in the Document Tree). | | |
@SELECT - use the results of a query to the database. | | |
@EVAL - use the output of given PHP code. | | |
@INHERIT - inherits the value of the same TV as set for a parent document. | | |
@DIRECTORY - a list of files in the given directory. The list output uses || as a delimiter. | | |
The content of chunks and documents are inserted directly into the document object being parsed, and any MODx tags in that content are processed on the next pass of the parser. It would be possible for the maximum number of passes (10, as set in the index.php file) to be reached, in which case the MODx tags would not be processed but rather displayed in the final page. If this were to occur, it would most likely be a good idea to re-think the design and structure of your template and content. However, most instances of MODx tags not being processed are caused by misspelling the name of the MODx element in the tags. | | |
The @EVAL binding simply takes the argument and passes it as a parameter to the PHP eval() function. The value of the TV will be the returned value of the eval() function, so the PHP code needs to start with the return function: | | |