I am passing a variable $courses to a smarty template. Here is what a print_r($courses) yields. The [requirements] element is actually another associative array which makes this operation a little trickier than what I'm used to.
Array ( [0] => Array ( [link_to_edit] => catalog_f06_edit.php5?id=1 [link_to_add] => catalog_f06_add.php5?id=1 [requirements] => Array ( [0] => Array ( [title] => Anthro book [ISBN] => 6544231 [edition] => sixth [author_last] => Smith [editor_last] => Meyers ) ) [crn] => 93208 [subject] => ANTH [section] => 250 [course] => Anthro [inst_last] => James[inst_first] => Billy) )
Here is what my template looks like:
Code: Select all
{section name=course loop=$courses}
{if $courses[course].inst_last == ""}
<strong>CRN: </strong>{$courses[course].crn} <strong>Subject: </strong>{$courses[course].subject} <strong>Section: </strong>{$courses[course].section} <strong>Instructor: </strong>{$courses[course].inst_first}<br />
{else}
<strong>CRN: </strong>{$courses[course].crn} <strong>Subject: </strong>{$courses[course].subject} <strong>Section: </strong>{$courses[course].section} <strong>Instructor: </strong>{$courses[course].inst_last}, {$courses[course].inst_first}<br />
{/if}
{section name=book loop=$courses[course].requirements}
<a href="{$courses[course].link_to_edit}">{$courses[course][book].title}: {$courses[course][book].ISBN}: {$courses[course][book].edition}</a><br />
{/section}
<a href="{$courses[course].link_to_add}">Teachers: add a course required book</a><br />
{/section}