Hi
Sorry if this has been asked but I'm really struggling here. I've just got back from holiday so maybe I'm just being thick.
I've created a custom views-view-fields.tpl.php file in which I display various HTML depending on what's in put in a field
For this content-type I have a boolean checkbox field, which I've set to "on" for true and "off" for false. I know that it's working as I have <?php print $field->content; ?>
or $fields['field_under_offer']->content;
and it displays "on" or "off" depending on whether it's checked or not. But I actually want to display different HTML depending on this.
I have an if statement <?php if ($fields['field_under_offer']->content === "on"): ?>
but it just doesn't work. Can someone tell me what the correct way of getting the checkbox value is?
Here's my full code. thanks very much for any help
<?php if ($field->label === "Under Offer") { ?>
<?php if (isset($field->content)): ?>
<?php if ($field->content === "on"): ?>
<?php print $field->content; ?>
<?php print "This is on"; ?>
<?php else : ?>
<?php print $field->content; ?>
<?php print "This is off"; ?>
<?php endif; ?>
<?php endif; ?>
<?php } ?>
Comments
Did you find solution?
Hello James,
I'm trying to do something similar but I can't get it to work. I tried your method but i had no luck.
Did you manage to find solution?
Thank you :)
Is the last bit of code from
Is the last bit of code from views-view-fields.tpl.php file? If so, is $field obtained by looping through the $fields array? Can you tell us what it does print out?
Try
print "<pre>" . $field->content . "</pre>" ;
and see whether any markup has been added.If so you can try
if ( FALSE !== strpos($field->content, 'on') )
orif ( $field->raw == 'on' )
.Hide a field based on a boolean field on the same node
I had a scenario where I wanted to use a boolean field on a node to control whether a Read More link was shown when displaying the node.
This code worked for me:
This checked if the boolean value ($field_show_read_more) was set to 1, and then displayed the Read More link if it did.
I provide Drupal, Drupal Commerce and CiviCRM development services for customers in New Zealand and beyond
Thank you millionleaves, that
Thank you millionleaves, that worked well for me.