Is there a way to set the default value of a TV to be the entered value of another TV?
We have what is essentially a category template with a TV listing the product id numbers. A new snippet function will be limited to less than four products, so for categories with less than four, we would use the original string, but for categories with more we would create a select list of four.
While I could build a check tv2 if not use tv1 function into the snippet, I am wondering if my question is possible.
I am referring to Template Variables, which allow a default value. I am wanting to set the value of TV called TopProduct equal to TV called AllProducts, unless I have entered a different value into TV TopProduct. So the default value of TV TopProduct would be equal the current TV AllProducts for that Resource.
Do you want to change that value in the database, on the backend or do you simply want to show a different value on the front end? Here it sounds like you want to fix the backend value of the tv, unless its already got a value.
I think you will need a php snippet to do this? Just spitballing here.
I’m afraid I’m still not understanding you. TVs only have one default value regardless of the Resource. So changing the default value of TopProduct would affect the values used for that TV for all Resources that do not have a value set for TopProduct. I don’t think that’s what you want, but I could be wrong.
It’s quite doable to set the value of TopProduct (if it’s empty) to the value of AllProducts for the current resource in a plugin attached to OnDocFormSave, but that would work best if the default value for TopProduct was empty, imo.
Sorry if my terminology is incorrect, I am just a casual user of MODX not a trained developer.
Basically I want the value of the first TV to automatically be inserted into the second TV, but if I manually enter something into the second TV it would retain that manually entered value (same basic function a TV ‘default’ value would have).
If I’m understanding you, and I’m not sure I am, if (and only if) there’s no value for TopProduct when you save the resource, you want the value from AllProducts to be used for it. If there is a value for TopProduct, that value will be used instead.
If that’s the case, this plugin attached to OnDocFormSave might do the job.
Just create a Plugin (name it whatever you want), paste in the code, and on the “System Events” tab, put a check next to OnDocFormSave, save the plugin, and you should be in business (assuming that my untested code works).
Actually I am thinking to take a different approach and test for the TV during the build process for the static website. That way I can add values to the few resources that need them and not have to go through every existing resource and resave it to run the plugin idea.