2023-02-06 14:42:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# truncate
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-03 11:59:22 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								This truncates a variable to a character length, the default is 80. As
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								an optional second parameter, you can specify a string of text to
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								display at the end if the variable was truncated. The characters in the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								string are included with the original truncation length. By default,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								`truncate`  will attempt to cut off at a word boundary. If you want to
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								cut off at the exact character length, pass the optional third parameter
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								of TRUE.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-06 14:42:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Basic usage
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```smarty
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{$myVar|truncate:40:"..."}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2021-12-03 11:59:22 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-06 14:42:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Parameters
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-03 11:59:22 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-06 14:42:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								| Parameter Position | Type    | Required | Default | Description                                                                                                                                                                                        |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								|--------------------|---------|----------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								| 1                  | integer | No       | 80      | This determines how many characters to truncate to.                                                                                                                                                |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								| 2                  | string  | No       | \...    | This is a text string that replaces the truncated text. Its length is included in the truncation length setting.                                                                                   |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								| 3                  | boolean | No       | FALSE   | This determines whether or not to truncate at a word boundary with FALSE, or at the exact character with TRUE.                                                                                     |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								| 4                  | boolean | No       | FALSE   | This determines whether the truncation happens at the end of the string with FALSE, or in the middle of the string with TRUE. Note that if this setting is TRUE, then word boundaries are ignored. |
							 
						 
					
						
							
								
									
										
										
										
											2021-12-03 11:59:22 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-06 14:42:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Examples
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-03 11:59:22 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-06 14:42:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								```php
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< ?php
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2021-12-03 11:59:22 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-06 14:42:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								where template is:
							 
						 
					
						
							
								
									
										
										
										
											2021-12-03 11:59:22 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-06 14:42:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								```smarty
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{$articleTitle}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{$articleTitle|truncate}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{$articleTitle|truncate:30}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{$articleTitle|truncate:30:""}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{$articleTitle|truncate:30:"---"}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{$articleTitle|truncate:30:"":true}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{$articleTitle|truncate:30:"...":true}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{$articleTitle|truncate:30:'..':true:true}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2021-12-03 11:59:22 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								This will output:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-06 14:42:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Two Sisters Reunite after Eighteen Years at Checkout Counter.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Two Sisters Reunite after Eighteen Years at Checkout Counter.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Two Sisters Reunite after...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Two Sisters Reunite after
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Two Sisters Reunite after---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Two Sisters Reunite after Eigh
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Two Sisters Reunite after E...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Two Sisters Re..ckout Counter.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2021-12-03 11:59:22 +01:00