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

First letter / substr or 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
antiheld2000
Smarty n00b


Joined: 23 Jun 2008
Posts: 4

PostPosted: Wed Feb 03, 2010 9:51 am    Post subject: First letter / substr or truncate Reply with quote

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
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Wed Feb 03, 2010 2:34 pm    Post subject: Reply with quote

The problem may be the dash "-" in the var name, did you try a var without a dash?
Back to top
View user's profile Send private message Visit poster's website
antiheld2000
Smarty n00b


Joined: 23 Jun 2008
Posts: 4

PostPosted: Wed Feb 03, 2010 3:34 pm    Post subject: Reply with quote

Thanks, good hint. This is the correct code:
Code:
{assign var=firstletter value=$entry->company_name|substr:0:1}
Back to top
View user's profile Send private message
alouty
Smarty Rookie


Joined: 07 Sep 2012
Posts: 8

PostPosted: Sun May 04, 2014 11:37 am    Post subject: Reply with quote

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
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