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 or Template 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.)

Installing ShowTv

Go to Extras -> Installer on the main menu in the MODX Manager and click on the "Download Extras" button. That will take you to the Revolution Repository. Put ShowTv in the search box and press Enter.Click on the "Download" button. When the download is finished, click on the "Back to Package Management" button. That should bring you back to your Package Management grid. Click on "Install" next to ShowTv.

Usage

[[!ShowTv? &tvID=`12` &resourceID=`14` &render=`0`]]

The example above will show TV 12's raw 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).

If the TV has no value for the specified Resource, the result will be empty unless the TV has a default value, in which case that will be used.

Note that for some TV types, (e.g., date TVs) the non-rendered ("raw") value of the TV may not actually be the raw value from the database. MODX may alter those in the process of retrieving them.

If you have TVs that contain sensitive information and Manager users who can edit Resources, remember that any such use will be able to see the value of those TVs if they know, or can guess the Resource ID and TV ID.

ShowTv Properties

The properties are case-sensitive, so be careful to type them correctly.

Property Description Default
resourceID ID of the Resource you want the TV value for (none)
tvID Name or ID of the TV (none)
render Render the TV's output 0

 

My book, MODX: The Official Guide - Digital Edition is now available here. The paper version of the book may still be available from Amazon.

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