ShowTV Snippet Tutorial
If you use this extra and like it, please consider donating. The suggested donation for this extra is $5.00, but any amount you want to give is fine (really). For a one-time donation of $50.00 you can use all of my non-premium extras with a clear conscience.
Sometimes you want to display the value of a Template Variable (TV) that is not connected to the current Template and/or the current Resource. The ShowTv Snippet allows you to display any TV on any page, even if the TV is not connected to the current Resource in any way.
Note that if you want some single value to be available throughout the site, the best way to do that is usually a System Setting (or a Context Setting). This Snippet is for when you have a TV that has different values for different Resources and want to show that TV's value for a particular Resource within some other Resource, Chunk, or Template.
(Jump to Properties Table.)
Go to System | Package Management on the main menu in the MODX Manager and click on the "Download Extras" button. That will take you to the Revolution Repository (AKA Web Transport Facility). Put ShowTv in the search box and press Enter. Click on the "Download" button, and when it changes to "Downloaded," click on the "Finish" button. That should bring you back to your Package Management grid. Click on the "Install" button next to ShowTv in the grid. The ShowTv package should now be installed.
[[!ShowTv? &tvID=`12` &resourceID=`14` &render=`0`]]
The example above will show TV 12's value for Resource 14. The first two properties are required. The third is optional (it defaults to 0). The Resource ID is shown in parentheses after the Resource name in the Resource tree. The TV ID is shown in parentheses next to the TV name in the Element tree.
If &render=`1`, the snippet tag will be replaced by the rendered value of the TV (for example, a date TV with a specified format or an image TV). If not, it will be replaced by the raw value of the TV. Showing the raw value is faster and will work in many cases (e.g., a text TV).
The name of the snippet and the properties are case-sensitive, so be careful to type them correctly or the snippet will not work.
|resourceID||ID of the Resource you want the TV value for||(none)|
|tvID||ID of the TV||(none)|
|render||Render the TV's output||0|
If you have the book and would like to download the code, you can find it here.
If you have the book and would like to see the updates and corrections page, you can find it here.
MODX: The Official Guide is 772 pages long and goes far beyond this web site in explaining beginning and advanced MODX techniques. It includes detailed information on:
- Installing MODX
- How MODX Works
- Working with MODX resources and Elements
- Using Git with MODX
- Using common MODX add-on components like SPForm, Login, getResources, and FormIt
- MODX security Permissions
- Customizing the MODX Manager
- Using Form Customization
- Creating Transport Packages
- MODX and xPDO object methods
- MODX System Events
- Using PHP with MODX
Go here for more information about the book.
Thank you for visiting BobsGuides.com
— Bob Ray