My content page:
"This is my website." -> This is my website.
{content assign="myvalue"}
{assign var="key1" value="website"}
{assign var="changeto" value="<a href='#link1' title='Title Key 1'>{$key1|capitalize}</a>"}
{$myvalue|replace:"`$key1`":"`$changeto`"}
I want:
{content assign="myvalue"}
{assign var="key1" value="my"}
{assign var="key2" value="website"}
{assign var="changeto1" value="<a href='#link1' title='Title Key 1'>{$key1|capitalize}</a>"}
{assign var="changeto2" value="<a href='#link2' title='Title Key 2'>{$key2|capitalize}</a>"}
With a key 1
{$myvalue|replace:"`$key1`":"`$changeto1`"}
and key 2 and ...
{$myvalue|replace:"`$key2`":"`$changeto2`"}
=> could replace more text in one {content assign="myvalue"}
Thanks,
Replacing text with a variable in content
- angelpeace
- Forum Members
- Posts: 39
- Joined: Fri May 15, 2009 9:45 am
Re: Replacing text with a variable in content
You could use the php function str_replace:
Actually when looking at the code for the modifier replace it is a wrapper for str_replace so you use it as:
Code: Select all
{content assign="myvalue"}
{assign var="key1" value="my"}
{assign var="key2" value="website"}
{assign var="changeto1" value="<a href='#link1' title='Title Key 1'>{$key1|capitalize}</a>"}
{assign var="changeto2" value="<a href='#link2' title='Title Key 2'>{$key2|capitalize}</a>"}
{[$key1,$key2]|str_replace:[$changeto1,$changeto2]:$myvalue}
Code: Select all
{$myvalue|replace:[$key1,$key2]:[$changeto1,$changeto2]}