I’ve got 2 template variables that are tied to a 3rd party webservice (not channel/entries) and when I try {count} or {switch} it is always 1 or doesnt switch
{exp:mythirdparty:userinfo}
{first_name} {last_name}
{call_history}
{count} {call_date} {call_person}
{/call_history}
{transactions}
{count} {trans_date} {trans_amt}
{/transactions}
{/exp:mythirdparty:userinfo}Every count is 1, which I’m assuming because there is only 1 userinfo record
Is it possible to count when looping in a nested tag or do you need to bake in your index/increment into the arrays
Bumping this because I’ve not yet found a good solution other than rolling my own {index} variable into my custom loops.
For instance:
{workbook_entries}
<h3>{entry_title}</h3>
{if entry_index < 2}
{entry_body}
{/if}
{/workbook_entries}I’ve looked at the switch tag which doesn’t appear to be appropriate since it’s meant for rotating through values.
Are you using $this->EE->TMPL->parse_variables() in your addon?
We’re using parse_variables, I just realized though that the {count} and {total_results} is only generated for the outermost array of the template variables. We might reorganize some calls to alleviate this issue or make use of some {embed} calls.
For instance this doesn’t create {count} for the inner array ‘articles’
$vars = array(
array(
'section' => 'foo',
'articles' => array(
array('article_id' => 3, 'summary' => '...',
array('article_id' => 5, 'summary' => '...')
)
),
array(.....)
);template
{exp:our_call}
Here are the articles for {section}
outer count: {count} {!-- this is valid --}
<ul>
{articles}
<li>{count}: {summary}</li> {!-- this is NOT valid --}
{/articles}
</ul>
{/exp:our_call}This seems potentially like a bug, considering the fact that the array loop {articles} is parsed and therefore no reason it can’t have its own {count}, like we did manually. I can see a problem with variable name collision, but could be worked around by incrementing the count and total_results variables, like using {count_1} in the {articles}..{/articles} loop.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.