Prakash
Prakash

Reputation: 2723

adding content in the middle of smarty variable

how can I modify a smarty variable on tpl file and add some data after certain position without using php? is it possible?

suppose,

$var="this is test content for a variable";

and i want to add "EXTRA DATA " after 8th character position so that the final output will be "this is EXTRA DATA test content for a variable"

Upvotes: 0

Views: 313

Answers (2)

Roshan Wijesena
Roshan Wijesena

Reputation: 3136

yes you can truncate the sentencen use http://www.smarty.net/docs/en/language.modifier.truncate.tpl

then add your extra word as smarty varible

Upvotes: -1

Rudi Visser
Rudi Visser

Reputation: 21989

You could do it like this:

{$var|substr:0:8}EXTRA DATA {$var|substr:8}

May I ask why you're not wanting to do this in PHP? It's more suited there, this is not the job that a template should be doing.

Upvotes: 2

Related Questions