All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

{count} inside a low_variables:parse tag is being overridden by the channel:entries {count}.

jannis 22 May 2012 09:12 problem, complete

Hi Low,

I'm running into an issue where I have a snippet which uses a Low Vars select fieldtype to bring a bunch of text items into a specific order.

Each item in the template gets assigned a number (it's position in the order).

eg: 01 - Home, 02 - Projects, 03 - About

I've got the select fieldtype parsing out using the {exp:low_variables:parse var="lv_nav_order" multiple="yes"} tag pair but within this tag pair trying to use {count} only outputs 01 01 01 since the snippet itself is run from within a channel entries loop which is limited to 1.

Is there any way of simply outputting the number of the item in the order that the client has ordered the select list inside Low Vars that doesn't conflict with the channel entries {count} variable?

Thanks for reading!

PS: I've tried setting the select fieldtype to parse early but that doesn't help either.

Replies

  1. Low 22 May 2012 09:24

    Ah yes, that's because the {count} var (and {total_results} for that matter) is added automatically by EE. I'll need to add my own count-var to avoid conflicts, but that isn't in place right now. So that would require a little hack, at least until I add a workaround to the core.

  2. jannis 22 May 2012 09:27

    Thanks for the quick reply!

    A hack would be fine by me, only my PHP skills are not good enough to figure out how to make this happen myself and I have just discovered this on a live site of mine.

    So for the moment the site is getting hardcoded numbers but should the order of those select items change I will get a phone call for sure :)

    Any chance you could tell me what code place where in what file to make this happen in my local install until you have had a chance to make it part of the default fieldtype/module?

    Many thanks again.

  3. Low 22 May 2012 09:39

    Sure, open up mod.low_variables.php and go to line #162. That should read $data = array();
    Below that, add these lines:

    $i = 0; 
    $total = count($value_array);


    Then, just a bit lower (now line #174) you'll see // Legacy vars.
    Above that, add these lines:

    $var.':count' => ++$i, 
    $var.':total_results' => $total,


    After that, you should be able to use the vars {lv_nav_order:count} and {lv_nav_order:total_results}.

    Of course, back up your stuff before you do.

  4. jannis 22 May 2012 09:43

    Awesome, that worked great!

    Thanks a lot for the quick help. Much appreciated.

  5. Low 22 May 2012 09:44

    Cool. Consider it added to the next version, so no need to worry about maintaining the hack.