Template Variables Not Displaying For Certain Resources


I have created a snippet that creates new resources, setting their template to a specific ID, and setting their template tags. This appears to work correctly, with the resources appearing published in their appropriate directories, and with the appropriate template tags in the manager.

The issue that I am having is that although I can see that one of my new resources has a template tag with an appropriate value when I view it in the manager, when I attempt to display the value of the template tag in the front-end using [[*template-tag]], no value is displayed, even though I know that the template tag has a value. Although this one specific template variable is not displaying for this resource, it appears that most of the other template variables are displaying without any issue. For whatever reason, this behavior only appears to be occurring in the new resources that have been created and that have had their template variables set through the setTVValue method call with my snippet, as previously created resources using the same template display this template variable value without any issues.

When researching this problem I saw that the issue might have to do with my cache, and it seemed as though I would be able to tell if this was a caching problem by viewing this page through a private browser. When I view the page using private browsing mode the issue persists on the new resources, so as far as I can tell this is not a caching issue.

Does anyone know why certain resources are having difficulty displaying this specific template variable?

Do the TV values (that don’t get displayed) exist in the database?
Check the table modx_site_tmplvar_contentvalues if there is a corresponding entry (column “contentid” = Resource-ID, column “tmplvarid” = TV-ID).

If you manually clear the MODX cache in the manager (menu “Manage” → “Clear Cache”), do the missing TV values now get displayed?

Look also for earlier entries in the table halftrainedharry mentioned with the same corresponding contentid and tmplvarid values, but an empty value field.

Sometimes, during development of a snippet like yours, faulty modTemplateVarResource entries get created. They can hang around and cause trouble later.

1 Like