Bindings
Last updated Feb 8th, 2023 | Page history | Improve this page | Report an issue
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$306 per month—let's make that $500!
Learn moreWith at-bindings, you can define a dynamic data source for a template variable. Typically used for selectbox or checkbox TVs, where the editor can choose one or more relevant options that are dynamically shown.
For example:
- an externally generated file that is sent via FTP to the server
- a database table accessible to MODX
- a Resource in the resource tree
- a Chunk in the Elements tree
- the result of an evaluated PHP script
These Data Sources can be tied (or "bound") to a Template Variable for formatting and displaying in document. In addition, the bound data in the TVs can be almost effortlessly formatted via the Display Controls within the TV system for some truly stunning results. The format for using the types of data source bindings available to all template variables follows:
- @FILE file_path
- @RESOURCE resource_id
- @CHUNK chunk_name
- @SELECT sql_query
- @DIRECTORY path_relative_to_base_path
- @INLINE available in some Extras (e.g. getResources), this specifies a formatting chunk in-line as a string.
These "@" commands or bindings will allow you to quickly and easily attach your template variables to virtually any database system available.
The value returned from the data source can either be a string value (including numbers, dates, etc), an array or a recordset. The value returned is dependent on the type of binding used. Some display controls will attempt to either convert the returned value into a string or an array.
For example, controls that accept string values such as a radio button group or select list will attempt to convert a record set (rows and columns) into the following format:
col1row1Value==col2row1Value||col1row2Value==col2row2Value,...
Note that @-bindings only work inside "Input Option Values" or "Default Value" fields.
When placing @ bindings inside the "Input Option Values" field, they are used to format input options only when editing document within the Manager, for example to create a drop-down list of Cities or Countries.
When placing @ bindings inside the "Default Value" field the returned value is used to render to the final web page. This makes it simple to build complex forms for data input on the web very quickly.
Types¶
Certain extras, such as getResources, support @INLINE
or @FILE
bindings for their chunks.
See Also¶
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$306 per month—let's make that $500!
Learn more