Page 1 of 1

smarty templates {section}

Posted: Mon Apr 03, 2006 2:44 pm
by jonathant
I might have been able to find the answer to this question on the smarty site, but apparantly they were hacked today. Anybody know the story on that?

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}
The outside section is printing ok, but the section is not. What am I missing?

Posted: Mon Apr 03, 2006 3:26 pm
by jonathant
Fixed it, but in case you were wondering the solution:

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].requirements[book].title}: {$courses[course].requirements[book].ISBN}: {$courses[course].requirements[book].edition}</a><br />
		{/section}
		<a href="{$courses[course].link_to_add}">Teachers: add a course required book</a><br />
{/section}