View previous topic :: View next topic |
Author |
Message |
machnhed1 Smarty Regular
Joined: 21 Apr 2003 Posts: 39 Location: Illinois
|
Posted: Wed Jun 25, 2003 3:06 pm Post subject: Opposite of Truncate |
|
|
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 _________________ "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 |
|
Enquest Smarty Regular
Joined: 14 May 2003 Posts: 79
|
Posted: Wed Jun 25, 2003 3:22 pm Post subject: |
|
|
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 |
|
machnhed1 Smarty Regular
Joined: 21 Apr 2003 Posts: 39 Location: Illinois
|
Posted: Wed Jun 25, 2003 3:28 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jun 25, 2003 3:51 pm Post subject: |
|
|
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 |
|
machnhed1 Smarty Regular
Joined: 21 Apr 2003 Posts: 39 Location: Illinois
|
Posted: Wed Jun 25, 2003 4:03 pm Post subject: |
|
|
Is there a tutorial (or example) on modifying variables? If so, please post the link. I didn't see anything on the site.
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 |
|
sweatje Smarty Regular
Joined: 17 Apr 2003 Posts: 70 Location: Bettendorf, Iowa, USA
|
Posted: Fri Jun 27, 2003 3:00 am Post subject: |
|
|
in a template
should work, but unless you are in <pre> or <code> HTML will just eat the spaces anyway... _________________ Jason
jsweat_php AT yahoo DOT com |
|
Back to top |
|
machnhed1 Smarty Regular
Joined: 21 Apr 2003 Posts: 39 Location: Illinois
|
Posted: Fri Jun 27, 2003 1:04 pm Post subject: |
|
|
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 |
|
|