Hello,
I just created a Template Variable with the input type "Checkbox".
the input option value is "LastNews" and the default value is also "LastNews".
(I want webmasters to be able to switch on/off the last news section on each page)
In a snippet I read the TV:
$tv = $modx->getTemplateVar(’LastNews’, "", $modx->documentIdentifier);
$x = $tv["value"];
I would expect that one of the elements in the $tv structure indicated if the
checkbox is checked or not for this page.
But, in both instances (checked and unchecked) I get the same structure data back.
So, the question is: How can I check if a Checkbox Template Variable is checked
for a certain page (document).
Thanks in advance for your help.
Hello,
I found what it was:
The Template Variable has a field called "Input Option Values". In there I store the string "1".
I leave the Default Value field empty.
Then in my page I see a checkbox which is unchecked.
Then, the element ’value’ in the structure has no value.
If I change the TV in the page to checked, then the element ’value’ get the value of the ’Input Opiotn Values’.
So far this is all expected bahaviour.
But, when I give the field "Default Value" in the Template Variable screen also the value "1",
then thing go wrong:
- The checkbox in my page is checked. (Expected behaviour)
- Then I uncheck this an do a save.
- Then I check the structure and see that it still have the value "1".
This is wrong.
But I understand the bug now: Since the unchecked state is indicated
by giving the ’value’ no value, MODX fills in the Default Value.
So, do not fill in the Default Value in a Template Variable if your input type
is a checkbox.
Is this a correct assumption?
Regards,
Bert Catsburg