7

I have a problem where I need to increment a variable if it satisfies a conditional like so:

{matrix_tag_pair}
  {if matrix_column_name}
    $increment++
  {/if}

  {if $increment > 9}
    do this...
  {if:else}
    do that...
  {/if}
{/matrix_tag_pair}

Is it possible to do this without enabling PHP in a template? I don't see where you can create throwaway variables like counters using just EE template tags.

Solution: Increment was close enough that I modified the source so it could also return the count without incrementing.

{exp:pvl_increment start="0" step="1"}
{matrix_tag_pair}
  {if matrix_column_name}
    {exp:pvl_increment random}
  {/if}

  {if {exp:pvl_increment increment="no" random} > 9}
    do this...
  {if:else}
    do that...
  {/if}
{/matrix_tag_pair}

Thank you for pointing me in the right direction. This was enough that I didn't have to enable PHP in my template. This slightly modified version of Increment combined with Loop Plus could be a very useful combination.

2
  • 1
    If anybody also thinks this is useful, I've got the forked addon source over at github.com/ginghamsburg/Pvl_increment I've submitted a pull request to the author to roll it into the next version. Commented Nov 29, 2012 at 19:43
  • Push merged. Thanks for your contribution!
    – pvledoux
    Commented Nov 29, 2012 at 21:18

1 Answer 1

6

I haven't used it myself, but perhaps the Increment plugin could do what you need? Or at least provide a basis for development. At the moment it always returns the current increment value, but it would be pretty easy to add a param to surpress this. Shout if you need help with that.

You would then do something like:

{matrix_tag_pair}
  {if matrix_column_name}
    {!--contains pseudocode! supress_output param doesn't exist in linked plugin as is, but could easily be added--}
    {exp:pvl_increment random id="my_id" supress_output="yes"}
  {/if}

  {if {exp:pvl_increment id="my_id"} > 10}
    do this...
  {if:else}
    do that...
  {/if}
{/matrix_tag_pair}
0

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.