How to check if one of checkboxes is checked?

I want to have setting to show/hide 3 fields independent of each other.

This rule shows “title” field only if one checkbox “title” is checked. But if any other checkbox is checked, then “title” is hidden.
<?php if ($page->settings_fields()->value() == "title"): ?>

How to make it work with any combination? For example, both “title” and “photo” options selected - then “title” should be shown.

if (in_array($page->settings_fields()->value(), ['a', 'b', 'c'])) {
  // this stuff will be done if the settings_fields field has either value a, b, or c;

Not quite sure what fields you have there? Looks like you have multiple fields, so the above won’t work.

It’s one checkboxes field with three options:

            type: checkboxes
              - value: 'cover'
                text: Show Image
              - value: 'title'
                text: Show Title
              - value: 'body'
                text: Show Body

So if either one or more of these options is checked, you want to do something? Then you could just check if the field is empty or not.

Actually I can just do 3 separate field for this, but in this case it’s to make it look more compact, as if I put fields in column with 1/3 width, it’s impossible to make width of inner fields 1/3, they take all space :slight_smile:

If “title” is checked, then I want to print “title” fields. If “cover” is checked, then “cover” fields should be printed. If both “title” and “cover” check, then both should be printed etc. So what is checked, should be printed.


And then I want to print each field depending on this:

  <?php if ($page->settings_fields()->value() == "title"): ?>
  <a href="<?= $project->url() ?>">
  <h2 class="h3 font-weight-bold"><?= $project->title() ?></h2>
  <? endif ?>

(sure, like I wrote, code is not working this way)

Oh, now I get it.

if (in_array('title', $page->settings_fields()->split(',')) {
    // print title;

etc. for the other field types.

Oh, clear, thank you very much! Tested, it works :slight_smile:

By the way, is it possible to set, that at least one value should be checked? As in this case it won’t make sense to uncheck all, as at least one field should be printed?

You would have to require the field.

:man_facepalming: sure, sorry :slight_smile: