ExpressionEngine Plugin: PipeBomb

This plugin was a quick response to a need to add multi-language capability to a module that I didn’t have time nor desire to hack into.

My client’s site was already using Mark Huot’s Simple Translator extension to provide multi-language capability so, for every weblog entry, we needed to create a custom field for each language (with the language’s suffix appended—e.g., body, body_es, body_pg). All was fine until I came across an interesting bugaboo presented by the LG Polls module (another beautiful piece of work from Leevi Graham). The module handled multiple custom fields for the poll question just fine, but for the poll details (the answers) there was to be none of that.

Fortunately, the client agreed to a rather unorthodox solution: rather than creating three custom fields, we’d use just one custom field with three fields piped inside—e.g., “English answer|Spanish answer|Portuguese answer”. Then in the template, we’d insert the PipeBomb plugin where we needed to parse those fields. In the following example, we switch between the three language responses based upon a match from EE’s “lang” cookie:

  1. {poll_answers}
  2. <li class='a-{answer_count}'>
  3. <label for="lg-polls-answer-{answer_id}">{answer_input} <span class="answer">{exp:pipebomb switch="lang" switch_type="cookie" cases="_es_pg" values="{answer}"}</span></label>
  4. </li>
  5. {/poll_answers}

Of course, this plugin has more uses:

  1. {exp:pipebomb switch="{dynamic_variable}" cases="1234" values="Number OneNumber TwoNumber ThreeNumber Four"}

And if you want to get really creative, you can loop and pipe a whole HTML fragment between categories tags:

  1. {exp:pipebomb switch="{simple_language}" cases="EnglishEspañolPortuguês" values="{categories backspace='1'}<h3><a href='{path='articles'}'>{category_name}</a></h3>{/categories}"}

For the curious, the PipeBomb name evolved from the way it works under the covers: it basically explodes piped values and plucks those values out of the array for display based upon the switch/case parameters.

NOTE: Just as I went to publish, I noticed that a very similar plugin called Switchee was recently released. I believe the two plugins are suitably different to coexist. PipeBomb is a small, crude device meant for quick, dirty jobs whereas Switchee is more of an industrial-strength switch/case utility.

Download PipeBomb

Article: Comment Feed

4 Comments (+)

  1. Lee Vrana

    I am very thankful to this topic because it really gives up to date information :~`

  2. resan flygbiljetter

    i’ve checked this site a couple of times now and i have to say that i find it quite good actually. keep it up! :)

  3. spelautomater

    Thanks for this great article. I am trying to read some more posts but I cant get your website to display properly in my Opera Browser. Thanks again.

  4. Brigida Wisenbaker

    Utterly composed content , Really enjoyed reading through .