Jump to content

Select Options classes based on selections


a-ok
 Share

Recommended Posts

Hi folks,

I am using the Select Options module to set up up options for content within a repeater (if the image you've added wants to be full, half or quarter width) and I have setup a few options:

1=Full

2=Half

3=Quarter

 
This all works fine in the admin end; but on the front end I am trying to determine, for each in the loop, which options was selected. I have it set up like this:
<div class="col-xs-12 <?php if ($image->issue_raw_image_width === 1) : ?>col-sm-offset-1 col-sm-10<?php elseif ($image->issue_raw_image_width === 2) : ?>col-sm-6<?php elseif ($image->issue_raw_image_width === 3) : ?>col-sm-3<?php else : ?>not-working<?php endif; ?>">

However, this isn't working at all; it just echos out my test 'not-working' class. If, for each, I ask it to echo out `$image->issue_raw_image_width` then it returns the correct value.

Any thoughts?

Link to comment
Share on other sites

echo use __toString() function and will return a string like '1'. In your case use API like:

$image->issue_raw_image_width // returns (string) '1'
$image->issue_raw_image_width->id; // returns (int) 1
$image->issue_raw_image_width->title; // returns 'Full'
$image->issue_raw_image_width->value; // returns ''

// settings: 1=Full|myvalue
$image->issue_raw_image_width->value; // returns 'myvalue'

Have a deeper look here: https://processwire.com/api/modules/select-options-fieldtype/#separate-option-values

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...