Problem with Checkbox custom attribute
Permalink
Hi,
I have a checkbox custom page attribute that I am getting in my pagelist+ template like so:
I was testing to see if it is checked like this:
But that was not showing the button in my code at all whether ticked or not.
So I changed it to:
Now it always shows the button in my code no matter whether it is checked or not.
To complicate matters, I set the attribute to be checked by default, but that doesn't seem to work.
Any ideas please? :)
Thanks
Dave
I have a checkbox custom page attribute that I am getting in my pagelist+ template like so:
$show_view_button = $page->getAttribute('show_view_button');
I was testing to see if it is checked like this:
<?php if ($show_view_button == "true"): ?> ... Show button ... <?php endif; ?>
But that was not showing the button in my code at all whether ticked or not.
So I changed it to:
<?php if (isset($show_view_button)): ?> ... Show button ... <?php endif; ?>
Now it always shows the button in my code no matter whether it is checked or not.
To complicate matters, I set the attribute to be checked by default, but that doesn't seem to work.
Any ideas please? :)
Thanks
Dave
Using var_dump(), a checked checkbox attribute is string(1) "1" and an unchecked checkbox attribute is string(1) "0".
This allows you to test for checked or unchecked based on the value of the variable.
Example:
When checking and unchecking the attribute, remember to refresh the page after saving. If you don't, you won't apply the updated value.