I’m trying to create module method that needs the support of nested pair tags.
For example:
{exp:module:method}
{product-category}
<div id="{category}">
{product}
<div = "{product-id}">
{poduct-info} {some-other-tags}
</div>
{/product}
</div>
{/product-category}
{/exp:module:method}Note: every tag pair can contain one or more rows.
If I don’t use nested tag-pairs, ie. just one, it works fine. But nested variables won’t work. Should this be possible or is it a limitation of the templating system?
http://ellislab.com/expressionengine/user-guide/development/usage/template.html#parsing_variables_pair_vars < this is the method I’m using. As in creating an multidimensional array and parse it all at once using the $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $variables); method.
If it is possible, can someone maybe post an example of the code and array that is fed to the parse_variables method?
Thanks for taking the time to read this!
I was confused by this at first as well. A tag pair’s variable array is not just a lone associative array, but an (indexed) array of (associative) arrays. So a tag pair is meant to loop through all of the rows of associative arrays, even if you are only using one “row” per tag pair.
$variables = array(
0 => array(
'product-category' => array(
0 => array(
'product' => array(
0 => array(
'product-id' => 1,
'product-info' => 'something',
'some-other-tag' => 'else',
),
1 => array(
'product-id' => 2,
'product-info' => 'other',
'some-other-tag' => 'test',
),
),
),
),
),
);Thanks again Rob, I get it now! It’s working as expected.
For other people struggling with the same issue, here again is Rob’s code but with the addition of the ‘category’ tag + example of more then 1 category.
$vars = array(
0 => array(
/* Product-category tag pair */
'product-category' => array(
0 => array(
/* Single var */
'category' => 'Category 1',
/* Product tag pair */
'product' => array(
0 => array(
/* Single vars */
'product-id' => 1,
'product-info' => 'something',
'some-other-tag' => 'else',
),
1 => array(
/* Single vars */
'product-id' => 2,
'product-info' => 'other',
'some-other-tag' => 'test',
),
), /* /Product tag pair */
),
1 => array(
/* Single var */
'category' => 'Category 2',
/* Product tag pair */
'product' => array(
0 => array(
/* Single vars */
'product-id' => 1,
'product-info' => 'again something',
'some-other-tag' => 'else',
),
1 => array(
/* Single vars */
'product-id' => 2,
'product-info' => 'another',
'some-other-tag' => 'test',
),
), /* /Product tag pair */
),
), /* /Product-category tag pair */
),
); /* /Main array */
$output = $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $vars);
return $output;Using this with:
{exp:module:method}
{product-category}
<div id="{category}">
{product}
<div = "{product-id}">
{product-info} {some-other-tag}
</div>
{/product}
</div>
{/product-category}
{/exp:module:method}Will produce:
<div id="Category 1">
<div = "1">
something else
</div>
<div = "2">
other test
</div>
</div>
<div id="Category 2">
<div = "1">
again something else
</div>
<div = "2">
another test
</div>
</div>Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.