Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Assign associative array with prefix/suffix

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
schaefner
Smarty n00b


Joined: 26 Mar 2005
Posts: 3
Location: Denmark

PostPosted: Sat Mar 26, 2005 8:36 pm    Post subject: Assign associative array with prefix/suffix Reply with quote

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
View user's profile Send private message Visit poster's website
schaefner
Smarty n00b


Joined: 26 Mar 2005
Posts: 3
Location: Denmark

PostPosted: Sat Mar 26, 2005 9:04 pm    Post subject: Re: Reply with quote

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
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Mar 28, 2005 7:05 pm    Post subject: Re: Assign associative array with prefix/suffix Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP