Skip to content

Instantly share code, notes, and snippets.

@newism
Created September 5, 2009 11:31
Show Gist options
  • Save newism/181382 to your computer and use it in GitHub Desktop.
Save newism/181382 to your computer and use it in GitHub Desktop.
<?php function render_collection($collection, $tagdata, $prefix = "", $depth = "0")
{
global $TMPL;
$count = 0;
foreach ((array)$collection as $key => $data)
{
++$count;
// print(str_repeat("&nbsp;&nbsp;", $depth). $prefix . $key."<br />");
if(is_array($data) || is_object($data))
{
if(preg_match("/".LD.$key.RD."(.*?)".LD.SLASH.$key.RD."/s", $tagdata, $matches))
{
$chunk = $matches[0];
$chunk_content = $matches[1];
foreach ($data as $data_key => $data_value)
{
if(method_exists("start_template_output", $data_value)) $data_value->start_template_output();
$tagdata = str_replace(
$chunk,
render_collection(
$data_value,
$chunk_content,
Inflect::singularize($key) . "_",
$depth + 1
),
$tagdata
);
}
}
}
else
{
$tagdata = $TMPL->swap_var_single($prefix . $key, $data, $tagdata);
}
$tagdata = $TMPL->swap_var_single($prefix . "count", $count, $tagdata);
}
return $tagdata;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment