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:
{poll_answers} <li class='a-{answer_count}'> <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> </li> {/poll_answers}
Of course, this plugin has more uses:
{exp:pipebomb switch="{dynamic_variable}" cases="12 3 4" values="Number One Number Two Number Three Number Four"}
And if you want to get really creative, you can loop and pipe a whole HTML fragment between categories tags:
{exp:pipebomb switch="{simple_language}" cases="EnglishEspañol Portuguê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.
January 19th, 2011 at 5:24 am
I am very thankful to this topic because it really gives up to date information :~`
January 28th, 2011 at 1:27 pm
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! :)
December 2nd, 2011 at 3:32 am
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.
December 26th, 2011 at 2:32 pm
Utterly composed content , Really enjoyed reading through .