4

Nice to see a Stack site for EE. Used S Overflow many times in past, and has always been much help.

Anyhow, heres my first question...

I have a site that lists dog walks. I have a checkbox field for the walks channel. Users submit walks via a safecracker form, and the checkbox field is used for users to select certain features present at the walk.

At the moment I display the field on the single entry view page, using the following...

<strong class="heading">Walk Features:</strong>
                <ul>
                  {walk_features}
                    <li>
                      <span>{item}</span>
                      <a href="{site_url}walk_location_features" target="_blank">Find out more</a>
                    </li>
                  {/walk_features}
                </ul>

This produces me a simple list on front end. Now I want to spice up that list slightly, by having a different icon/image & description for each option (contained within the checkbox field.)

So I need to output (HTML) something like:

<ul class="features">
<li class="option1">
    <h3>Option 1</h3>
    <p>A short description of option one</p>
</li>
<li class="option2">
    <h3>Option 2</h3>
    <p>A short description of option two</p>
</li>
etc

I'm just not quite sure on how to get to that from my checkbox field. I have had P&T checkbox field & Low Options suggested, however I am still unclear as to how I can get it from the current field.

I have over 130 entries which use this field, and was hoping that I could output it directly from the existing field. I could add a new field if necessary, and go through transferring the data, but I obviously would like t avoid that if possible! Any help greatly appreciated! :)

4

I suggest switching the field over to P&T Checkboxes or Radio Button (if you only want them to select one option). In the settings I would specify an option value separately from it's label:

option_one : Option 1
option_two : Option 2
option_three : Option 3

Then in your template use the option value as the class name:

<ul>
  {walk_features}
    <li class="{option}">
      <span>{option_name}</span>
      <a href="{site_url}walk_location_features" target="_blank">Find out more</a>
    </li>
  {/walk_features}
</ul>

Since you have 130 entries already, I suggest using a SQL query to find/replace all the entries with the new values. Be sure to backup your DB before doing this.

UPDATE
exp_channel_data
SET field_id_X = replace(field_id_X,'Option 1','option_one');

UPDATE To add a short description instead of a link:

<ul>
  {walk_features}
    <li class="{option}">
      <span>{option_name}</span>

      {if "{option}" == "option_one"}
        short description about Option 1
      {/if}

      {if "{option}" == "option_two"}
        short description about Option 2
      {/if}
      ...

    </li>
  {/walk_features}
</ul>
| improve this answer | |
  • Thanks for that reply. That is what I have had suggested. (Although I didn't know about the SQL Query find/replace.) Now this option works, apart from one part. Before, I had a the link to "Find out more", which was the same for each option, but I am looking at changing that to a short description of the option, as opposed to a link to another page. Any thoughts on how I can change that based on each option? (There are eight options in total, and each one will have a different accompanying 1-2 lines explaining it.) – shorn Dec 5 '12 at 13:07
  • Will the short description be editable in the channel entries? – Siebird Dec 5 '12 at 13:09
  • No, it will be 1-2 lines, specific to that option. – shorn Dec 5 '12 at 13:09
  • Updated my answer – Siebird Dec 5 '12 at 13:13
  • Brilliant, thought there would be some way via conditionals. I shall have a look now on my dev site and report back! Thanks. – shorn Dec 5 '12 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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