I am new to Cobalt templates and not well versed in PHP so my question may be very basic but I’ve been unable to resolve how to use a Boolean field in a Cobalt Type that I’ve created to track the status of a playing field for a local soccer club website.
In my template, I am able to obtain the Boolean field and display the Cobalt image/text. For example, when the field record’s Boolean field is set to true, the following code displays the tic.png and “Yes”:
<?php $field = $item->fields_by_id[64]; // Field Status ?>
<?php echo $field->result; ?>
What I am trying to do, instead, is to change the CSS class based upon the state of the record’s Boolean field using an if/else. However, the system fails even with the simplest if statements I’ve tried. For example:
This fails....
<?php $field = $item->fields_by_id[64]; // Field Status ?>
<?php if( $field->result == 'true' ) ?>
// CSS selection code will be placed here.
<?php endif; ?>
And this fails....
<?php $field = $item->fields_by_id[64]; // Field Status ?>
<?php if( ($field->result as bool) == 'true' ) ?>
// CSS selection code will be placed here.
<?php endif; ?>
Any insight you could provide to me would be greatly appreciated.
Thank you!
I am new to Cobalt templates and not well versed in PHP so my question may be very basic but I’ve been unable to resolve how to use a Boolean field in a Cobalt Type that I’ve created to track the status of a playing field for a local soccer club website.
In my template, I am able to obtain the Boolean field and display the Cobalt image/text. For example, when the field record’s Boolean field is set to true, the following code displays the tic.png and “Yes”:
What I am trying to do, instead, is to change the CSS class based upon the state of the record’s Boolean field using an if/else. However, the system fails even with the simplest if statements I’ve tried. For example:
This fails....
And this fails....
Any insight you could provide to me would be greatly appreciated. Thank you!