It seems that when a Template Variable has a default value, that default value is not stored in the database table: site_tmplvar_contentvalues for each page. Rather I am guessing it gets grabbed from: site_tmplvar at build time, whenever an alternate value was not entered for that page?
Is there a way to force MODX to save the TV even when it will have the default value? We would like to be able to access this data directly from the database for external PHP build functions.
Maybe you could write a custom plugin for the event OnDocFormSave that adds all the missing database entries (but you would work against the system as every time youâd save a resource, rows from modx_site_tmplvar_contentvalues would be deleted that you had to create then again).
One solution might be to set a dummy default value that would never be used (e.g, âXXXâ), then create a plugin that would automatically set the TVâs value to the ârealâ default value in, maybe in OnDocFormSave (or maybe OnBeforeDocFormSave) if itâs attached to the resourceâs template and no value is already set. MODX will only use the dummy default value if the TV has no value for the page.
At this point, if MODX doesnât have that built in, then it is probably just as easy to set the default value in our build script and then replace it if the database returns a value.
Thanks. That looks more like an âinside of MODXâ type solution, whereas our needs are for a totally independent system.
In a nutshell, we are using MODX as the M in JAMStack, generating static html pages to serve, plus json files for navigation by partial page hydration. And some of the TV values need to fetched independently as part of the json build process.
Yes we use MODX to create the pages. Then a separate system fetches the pages, saves a copy and extracts the changed content, saving that separately. Then everything gets uploaded to a CDN.
Some of the TVs are used in determing some of the extraction and build steps, so it helps when they can be easily pulled.