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

Opposite of Truncate

 
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 -> General
View previous topic :: View next topic  
Author Message
machnhed1
Smarty Regular


Joined: 21 Apr 2003
Posts: 39
Location: Illinois

PostPosted: Wed Jun 25, 2003 3:06 pm    Post subject: Opposite of Truncate Reply with quote

Hello,

I was wondering if there was a variable modifier (or a way to combine variable modifiers) in smarty so that a returned variable was allotted a certain number of spaces. For example...

$variable="This is a test."
$variable1="This is a much longer test with too many letters."

$variable has a character length of only 15 (including spaces), but I would like to lengthen it to a 30 spaces by adding blanks at the end of the displayed variable. On the other hand $variable1 has a character length greater than 30 (including spaces), but I would like to truncate it to a 30 spaces.

Truncate works very well for $variable1 but $variable has no modifier that works (I can't find it). Also, I am almost positive there is not modifier that will test a variable for both criteria and apply the appropriate modification.

Has anyone made a function that does this? Or is there is a variable that I am missing? Perhaps this should go on the wish list as this would make formatting tables (without html) very handy when using a font such as courier.

Thanks in advance to all that read this Exclamation
_________________
"Every operating system out there is about equal in the number of vulnerabilities reported. We all suck."

- Microsoft Senior Vice President Brian Valentine
Back to top
View user's profile Send private message
Enquest
Smarty Regular


Joined: 14 May 2003
Posts: 79

PostPosted: Wed Jun 25, 2003 3:22 pm    Post subject: Reply with quote

Add 15 spaces in your PHP code and send it then to smarty. I don't think this is something that Smarty should do. But hé I'm also a novice.

You could do this by counting the lengt of your variables.
Make the difrence between them and add & times the difrence.
Then your strings would be equel off lengt.

However the whole opperation sounds a bit over kill if you use tables. Just tell your table the whidt.

Hope I understood your question

Thanxs
_________________
-----------------------
Learning my self by trying to help others
Back to top
View user's profile Send private message
machnhed1
Smarty Regular


Joined: 21 Apr 2003
Posts: 39
Location: Illinois

PostPosted: Wed Jun 25, 2003 3:28 pm    Post subject: Reply with quote

I thought about your second option, and it is probably the only good solution for me. I could also create my own function and simply call that, but I was hoping someone had better (read more simple) solution.

I would like to use html, however the informaiton I am formatting is going into a non-html email, so I can't.

Thanks.
_________________
"Every operating system out there is about equal in the number of vulnerabilities reported. We all suck."

- Microsoft Senior Vice President Brian Valentine
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Jun 25, 2003 3:51 pm    Post subject: Reply with quote

You could modify the truncate modifier, add a new parameter and make truncate append this string of characters (repeatedly) in the event that the var is shorter than the truncation length.

Monte
Back to top
View user's profile Send private message Visit poster's website
machnhed1
Smarty Regular


Joined: 21 Apr 2003
Posts: 39
Location: Illinois

PostPosted: Wed Jun 25, 2003 4:03 pm    Post subject: Reply with quote

Is there a tutorial (or example) on modifying variables? If so, please post the link. I didn't see anything on the site.

Thanks Exclamation
_________________
"Every operating system out there is about equal in the number of vulnerabilities reported. We all suck."

- Microsoft Senior Vice President Brian Valentine
Back to top
View user's profile Send private message
sweatje
Smarty Regular


Joined: 17 Apr 2003
Posts: 70
Location: Bettendorf, Iowa, USA

PostPosted: Fri Jun 27, 2003 3:00 am    Post subject: Reply with quote

in a template
Code:
{$var|str_pad:30}

should work, but unless you are in <pre> or <code> HTML will just eat the spaces anyway... Rolling Eyes
_________________
Jason
jsweat_php AT yahoo DOT com
Back to top
View user's profile Send private message
machnhed1
Smarty Regular


Joined: 21 Apr 2003
Posts: 39
Location: Illinois

PostPosted: Fri Jun 27, 2003 1:04 pm    Post subject: Reply with quote

Jason,

The code is a complete success now. Thank you very much for the help.

Cheers!
_________________
"Every operating system out there is about equal in the number of vulnerabilities reported. We all suck."

- Microsoft Senior Vice President Brian Valentine
Back to top
View user's profile Send private message
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 -> General 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