0

I decided to undertake cleaning up some crazy repetitive code using the plugin Loopee, which we are already using. I briefly looked at Loop Plus, but that seems to only handle numbers, so I didn’t try testing nesting that one.

Anyway, I tried nesting Loopee tags, and the order the tags are looped is from the inside, opposite of how it would work if these were PHP loops. I’d like to know if anyone has experience nesting Loopee tags, why this works like this, and how I might resolve this issue. I’m not averse to patching the plugin if I can get some guidance on what I’d need to do.

An example:

{exp:loopee parse="inward" foreach="A|B" as="a"}
  {exp:loopee parse="inward" foreach="1|2" as="b"}
    {exp:loopee parse="inward" foreach="a|b" as="c"}
      {a}{b}{c}
    {/exp:loopee}
  {/exp:loopee}
{/exp:loopee}

Output: A1a B1a A2a B2a A1b B1b A2b B2b

As you can see, the outer Loopee tag’s A and B are alternating, while the innermost Loopee tag’s a and b are not alternating. To solve this simple example, I could swap the innermost and outermost Loopee tags, but that is both wonky and breaks code if I make use of the variables between the first Loopee start tag and the second.

For example, this is what I might like to do:

{exp:loopee parse="inward" foreach="amy|betty" as="name"}
  <h1>{name}</h1>
  {exp:loopee parse="inward" foreach="income|expenses" as="category"}
    <h2>{category}</h2>
    {exp:loopee parse="inward" foreach="1|2|3|4" as="quarter"}
      <p>
        <strong>{quarter}:</strong> {custom_field_here}
      </p>
    {/exp:loopee}
  {/exp:loopee}
{/exp:loopee}

But if I run that, I get the messed up looking output of (blank lines removed):

<h1>amy</h1>
  <h2>income</h2>
    <p><strong>1:</strong> {custom_field_here}</p>
<h1>betty</h1>
  <h2>income</h2>
    <p><strong>1:</strong> {custom_field_here}</p>
  <h2>expenses</h2>
    <p><strong>1:</strong> {custom_field_here}</p>
<h1>betty</h1>
  <h2>expenses</h2>
    <p><strong>1:</strong> {custom_field_here}</p>
    <p><strong>2:</strong> {custom_field_here}</p>
<h1>betty</h1>
  <h2>income</h2>
    <p><strong>2:</strong> {custom_field_here}</p>
  <h2>expenses</h2>
    <p><strong>2:</strong> {custom_field_here}</p>
<h1>betty</h1>
  <h2>expenses</h2>
    <p><strong>2:</strong> {custom_field_here}</p>
    <p><strong>3:</strong> {custom_field_here}</p>
<h1>betty</h1>
  <h2>income</h2>
    <p><strong>3:</strong> {custom_field_here}</p>
  <h2>expenses</h2>
    <p><strong>3:</strong> {custom_field_here}</p>
<h1>betty</h1>
  <h2>expenses</h2>
    <p><strong>3:</strong> {custom_field_here}</p>
    <p><strong>4:</strong> {custom_field_here}</p>
<h1>betty</h1>
  <h2>income</h2>
    <p><strong>4:</strong> {custom_field_here}</p>
  <h2>expenses</h2>
    <p><strong>4:</strong> {custom_field_here}</p>
<h1>betty</h1>
  <h2>expenses</h2>
    <p><strong>4:</strong> {custom_field_here}</p>

When what I want is output like this:

<h1>amy</h1>
  <h2>income</h2>
    <p><strong>1:</strong> {custom_field_here}</p>
    <p><strong>2:</strong> {custom_field_here}</p>
    <p><strong>3:</strong> {custom_field_here}</p>
    <p><strong>4:</strong> {custom_field_here}</p>
  <h2>expenses</h2>
    <p><strong>1:</strong> {custom_field_here}</p>
    <p><strong>2:</strong> {custom_field_here}</p>
    <p><strong>3:</strong> {custom_field_here}</p>
    <p><strong>4:</strong> {custom_field_here}</p>
<h1>betty</h1>
  <h2>income</h2>
    <p><strong>1:</strong> {custom_field_here}</p>
    <p><strong>2:</strong> {custom_field_here}</p>
    <p><strong>3:</strong> {custom_field_here}</p>
    <p><strong>4:</strong> {custom_field_here}</p>
  <h2>expenses</h2>
    <p><strong>1:</strong> {custom_field_here}</p>
    <p><strong>2:</strong> {custom_field_here}</p>
    <p><strong>3:</strong> {custom_field_here}</p>
    <p><strong>4:</strong> {custom_field_here}</p>

I am using EE 2.7.2

Thank you for your time!

0

I hope someone has a better solution than this, but for the time being, I found I can make copies of the Loopee plugin for each level of nesting I need. For example, I would duplicate the loopee directory and name it loopee2, and then rename the contained file pi.loopee2.php. Then I edit that file, changing these lines:

'pi_name'         =>  'Loopee2',
class Loopee2 {
function Loopee2()

That allows me to use a second level of nesting by calling the tag {exp:loopee2}.

(I also submitted an issue to the Github repo in case the plugin author has time and desire to tackle the issue.)

| improve this answer | |

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.