Skip to content

Instantly share code, notes, and snippets.

@jbroadway
Created July 24, 2013 13:30
Show Gist options
  • Save jbroadway/6070592 to your computer and use it in GitHub Desktop.
Save jbroadway/6070592 to your computer and use it in GitHub Desktop.
Looping examples in Elefant templates
<!-- apps/test/views/loops.html -->
<ul>
{% foreach my_array as my_key, my_value %}
<li>{{my_key}}. {{my_value}}</li>
{% end %}
</ul>
<hr />
<ul>
{% foreach my_array %}
<li>{{loop_index}}. {{loop_value}}</li>
{% end %}
</ul>
<hr />
<ul>
{% foreach my_array %}
<li>{{loop_index + 1}}. {{loop_value}}</li>
{% end %}
</ul>
<?php // apps/test/handlers/loops.php
echo $tpl->render (
'test/loops',
array (
'my_array' => range ('a', 'g')
)
);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment