|
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 |
antiheld2000 Smarty n00b
Joined: 23 Jun 2008 Posts: 4
|
Posted: Wed Feb 03, 2010 9:51 am Post subject: First letter / substr or truncate |
|
|
Hi,
i try to get the first letter of an entry, but i always get "0" instead of the real letter. Is this call correct or is there a mistake in the syntax?
Code: | 1. {assign var=$first-letter value='$entry->name|truncate:1:"":true'}
2. {assign var=first-letter value='$entry->name|substr:0:1'} |
A hint would be so nice.
Greetz
anti |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Feb 03, 2010 2:34 pm Post subject: |
|
|
The problem may be the dash "-" in the var name, did you try a var without a dash? |
|
Back to top |
|
antiheld2000 Smarty n00b
Joined: 23 Jun 2008 Posts: 4
|
Posted: Wed Feb 03, 2010 3:34 pm Post subject: |
|
|
Thanks, good hint. This is the correct code:
Code: | {assign var=firstletter value=$entry->company_name|substr:0:1} |
|
|
Back to top |
|
alouty Smarty Rookie
Joined: 07 Sep 2012 Posts: 8
|
Posted: Sun May 04, 2014 11:37 am Post subject: |
|
|
Looking to have code for first char for any words:
company_name : Smarty Php
The output is SP
company_name : Two Words
The output is TW |
|
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
|