|
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 |
szombe Smarty n00b
Joined: 15 Jul 2014 Posts: 4
|
Posted: Tue Jul 15, 2014 4:52 am Post subject: Replece singular and plural forms of words at the same time? |
|
|
Hey there folks! Need some help replacing both singular and plural forms of words. Example titles "He is eating a hamburger", "He is eating hamburgers".
How do I replace both at the same time? I want to replace words with links coming out from those words but both either hamburget or hamburgers no matter which one occurs in the description text.
Code: | {$text.descr|default:$text.text_title|replace:"hamburger":"<a target='_blank' href='http://www.hamburgerstore.bla-bla'><b>hamburger</b></a>"|replace:"hamburgers":"<a target='_blank' href='http://www.hamburgerstore.bla-bla'><b>hamburgers</b></a>"} |
This does not work, so if I do
Code: | {$text.descr|default:$text.text_title|replace:"hamburger":"<a target='_blank' href='http://www.hamburgerstore.bla-bla'><b>hamburger</b></a>"} |
This makes a link from any words containing hamburget, even hamburgets but the link does not include the s at the end. How do I fix this? First I thought of if cases like if the description contains hamburger, do replace with hamburger link, if it contains hamburgers do replace with hamburgers link.
{if $text.descr|strstr:"hamburgers"}
replace function here
{elseif $text.descr|strstr:"hamburgers"}
replace function here
{else}
title variable
...
Not even sure if the above will work because hamburger is contained in hamburgers as well.
Is there a more convenient way to do it or stack it?
Thanks! |
|
Back to top |
|
szombe Smarty n00b
Joined: 15 Jul 2014 Posts: 4
|
Posted: Thu Jul 17, 2014 12:34 pm Post subject: |
|
|
No chance? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jul 17, 2014 1:39 pm Post subject: |
|
|
Code: | {$text.descr|default:$text.text_title|regex_replace:"/\b(hamburgers?)\b/":<a href='foo'>$1</a>"} |
That will replace hamburger or hamburgers, but only if its not part of a longer word. |
|
Back to top |
|
szombe Smarty n00b
Joined: 15 Jul 2014 Posts: 4
|
Posted: Fri Jul 18, 2014 10:02 am Post subject: |
|
|
Will give it a try. Thanks! |
|
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
|