Re: [SMARTY] looping through variable names
Maximillian Schwanekamp <[email protected]>
| Newsgroups | gmane.comp.php.smarty.general |
|---|---|
| Message-ID | <[email protected]> |
Kathleen Krause-Thomson wrote:
> ...I need to
> loop through array variable names as if they were variable variables.
> How would I do this in Smarty?
> <p>Job Title: {$budget1.jobTitle}
> Percent of Full Time:{$budget1.percentFullTime}</p>
> Next section needs to be:...
From what you gave so far, it seems like you just need to assign your
array $budget, and use {foreach} to iterate over it. E.g.:
<?php
$budgets = array();
$budgets[] = array('jobTitle'=>'First Job', 'percentFullTime'=>100);
$budgets[] = array('jobTitle'=>'Second Job', 'percentFullTime'=>75);
//etc...
?>
{* smarty *}
{foreach from=$budgets item="budget"}
<p>Job Title: {$budget.jobTitle}
Percent of Full Time:{$budget.percentFullTime}</p>
{foreachelse}
<p>No budgets found.</p>
{/foreach}
If that doesn't answer the question, can you post your PHP, and [a
sample of] the array structure?
--
Max Schwanekamp
http://www.neptunewebworks.com/
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php