0

I am working with a template where items are filtered by their checkbox values. The each item can have multiple checkbox values, and when they are selected the checkbox values are separated with a comma.

example: The template looks like this:

<div class="{checkbox_values}"></div>

When multiple checkboxes are selected it looks like this:

<div class="value1, value2, value3></div>

I am using the isotope (http://isotope.metafizzy.co/) plugin to filter and sort my website values but isotope won't read the values with a comma after them. In the example above the only filter my filter function would read would be value3 (because it doesn't have a comma after it). Is there a way to customize the checkbox separator from a comma to a space? Or is there a different channel field that is better suited for something like this?

edit: This problem has been solved by adding some PHP to the replace the commas in the string of the class.

example:

<div class="<?php echo str_replace(",","","{checkbox_values}") ?>"></div>

1 Answer 1

1

YOu could simply strip the commas, as there's spaces in there already...

You can use a 3rd party plugin like String Replace Exp which is free :

<div class="{exp:strrexp pattern="," replace="" string="{checkbox_values}" }"></div>

Or you could drop a simple piece of PHP on the page like so

<div class="<?php echo str_replace(",","","{checkbox_values}") ?>"></div>

(PHP on Output)

5
  • Use this or Low Replace (or a similar string output mutilator), listen to this dude!
    – jrothafer
    Commented Jul 10, 2015 at 12:52
  • But no upvote JChrono?? :P jokes
    – Blatant
    Commented Jul 10, 2015 at 14:44
  • Lol sorry broheim, I've been drunk on a beach for a few days, so I'm playing the crazy catch-up game today. I ticked it for ya!
    – jrothafer
    Commented Jul 10, 2015 at 14:55
  • Thank you so much @Blatant and @jchrono-battle! I was actually looking into Low Replace, but wasn't sure I wanted to use a plugin. The PHP string replace answer that Blatant suggested worked perfectly. Thank you!
    – j_lemon
    Commented Jul 10, 2015 at 16:29
  • Happy to help :) Chose between extension or PHP or otherwise is a personal taste question in EE. For instance I'm PHP heavy, too heavy some would say, but thats becuase I'm a PHP developer for years before EE2 came along so I find it easier to just 'do what you need to do' instead of fighting parse order and the such. But others will bawk at this comment! Some say "if you can't do it with tags, don't do it"!!
    – Blatant
    Commented Jul 10, 2015 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.