|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
schaefner Smarty n00b
Joined: 26 Mar 2005 Posts: 3 Location: Denmark
|
Posted: Sat Mar 26, 2005 8:36 pm Post subject: Assign associative array with prefix/suffix |
|
|
I don't know if this "idea" is only good in my head but here it goes:
I think it would be nice to assign an associative array and prefix the keys with a defined string.
Something like this:
$mail['Subject'] = "Lorem ipsum";
$mail['Sender'] = "Jesper";
$mail['Body'] = "Lorem ipsum";
$inst->assignPrefixed($mail, "mail");
And get a result similar to this:
{$mailSubject}
{$mailSender}
{$mailBody}
Best regards
Jesper Soerensen |
|
Back to top |
|
schaefner Smarty n00b
Joined: 26 Mar 2005 Posts: 3 Location: Denmark
|
Posted: Sat Mar 26, 2005 9:04 pm Post subject: Re: |
|
|
Maybe something like this:
Code: | <?php
function assign_with_fix($tpl_var, $fix, $pos="P") {
if (is_array($tpl_var)) {
$pos = strtoupper($pos);
foreach ($tpl_var AS $key => $val) {
if ($key != '') {
$fixed_key = ($pos == "P") ? $fix.$key : $key.$fix;
$this->_tpl_vars[$fixed_key] = $val;
}
}
}
}
$mail['Subject'] = "Lorem ipsum";
$mail['Sender'] = "Jesper";
$mail['Body'] = "Lorem ipsum";
$smarty->assign_with_fix($mail, "mail");
$smarty->assign_with_fix($mail, "Mail", "S");
?>
{$mailSubject}
{$SubjectMail} // Maybe not that usefull |
Best regards
Jesper Soerensen |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Mar 28, 2005 7:05 pm Post subject: Re: Assign associative array with prefix/suffix |
|
|
hmm, you can assign the array like
$smarty->assign('mail', $mail)
and access the array's members as
{$mail.Subject}
{$mail.Sender}
{$mail.Body}
already. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|