Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>"In order to understand recursion, you must first understand recursion..."</p> <p>Just kidding. This should do what you want:</p> <pre><code>&lt;?php /* * Smarty plugin * ————————————————————- * File: function.recurse_array.php * Type: function * Name: recurse_array * Purpose: prints out elements of an array recursively * ————————————————————- */ function smarty_function_recurse_array($params, &amp;$smarty) { if (is_array($params['array']) &amp;&amp; count($params['array']) &gt; 0) { $markup = ''; $markup .= '&lt;ul&gt;'; foreach ($params['array'] as $element) { $markup .= '&lt;li&gt;'; $markup .= '&lt;h1&gt;' . $element['headline'] . '&lt;/h1&gt;'; $markup .= '&lt;p&gt;' . $element['body'] . '&lt;/p&gt;'; if (isset($element['children'])) { $markup .= smarty_function_recurse_array(array('array' =&gt; $element['children']), $smarty); } $markup .= '&lt;/li&gt;'; } $markup.= '&lt;/ul&gt;'; return $markup; } else { return 'not array'; } } </code></pre> <p>Place the file into your smarty/plugins folder. Assign your array to Smarty then call it in your template like so:</p> <pre><code>{recurse_array array=$data} </code></pre> <p>Here's nice tutorial for making custom Smarty functions: </p> <p><a href="http://www.velvetblues.com/web-development-blog/smarty-templates-create-custom-functions/" rel="noreferrer">Creating Custom Smarty Functions</a></p> <p>Be aware of the dependency that this example has on your underlying data structure. Also, keep in mind that an unusually long or deeply nested set of data could be really slow. Manage your complexity, keep things well documented, and you should be fine. Good luck!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload