Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
concatenate strings
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
messju
Administrator


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

PostPosted: Tue May 13, 2003 9:22 am    Post subject: Reply with quote

it doesn't work in 2.4.2 (as do backticks neither), but it works in 2.5.0 .
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Budda
Smarty Regular


Joined: 19 Apr 2003
Posts: 53
Location: Lymm, Cheshire. UK

PostPosted: Tue May 13, 2003 9:33 am    Post subject: oops! Reply with quote

Embarassed I could have swore I'd updated Smarty before Easter! But upon rechecking the Smarty.clas.php I found
Code:
 * @package Smarty
 * @version 2.4.2

hehe. Sorry guys.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
sergioabreu
Smarty n00b


Joined: 05 Sep 2013
Posts: 1

PostPosted: Thu Sep 05, 2013 5:42 pm    Post subject: I wrote a function to concatenate in smarty. Reply with quote

I've just written a function to concatenate texts in Smarty in a easy way.
First of all, you have to configure security to allow smarty using functions.

Declare this function in a php file that is loaded before invoking the template.

Code:

<?php
/**
* Smarty Concat. A php function that concatenates flexible length of parameters in Smarty.
* The first param is a Smarty variable to hold the result.
* From the second parameter till the last one they will be concatenated, and assigned automatically to the first parameter.
* CREDITS: Sergio Abreu
* http://sites.sitesbr.net
*/

   function smartyconcat( &$res ){       
       $args = func_get_args();       
       for( $i=1; $i < count($args); $i++){
            $s .= $args[$i];
       }       
       $res = $s;   
   }
?>


Usage:
Remember, the first parameter is the variable that will receive the concatenated result. Only the arguments at the right of the function will be concatenated (from the 2nd on).

{$myStr|smartyconcat:"one text":$one_variable:"other text":$anotherVariable}


After somewhere in the code you want to show it, just use:

{$myStr}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
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