|
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 |
marketingpro Smarty n00b
Joined: 26 Jun 2017 Posts: 3
|
Posted: Mon Jun 26, 2017 10:11 am Post subject: Smarty Conditionals (does not contain) |
|
|
Hi,
We are trying to customize our emails depending on a certain variable (product name). We need to send different content to the users that have a product name that doesn't contain a certain string/word.
We've managed to make it work when it contains a string {if $service_product_name|strstr:"WHATEVER"} but not when it does not contain a string.
We've tried {if $service_product_name is not "WHATEVER"} and {if $service_product_name % "WHATEVER"}, among other things, but they don't work.
Any clue?
Thanks! |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Jun 26, 2017 11:26 am Post subject: |
|
|
Please do not place business logic into templates.
Said that, you could use usual PHP string search functions in {if} block parameters. |
|
Back to top |
|
marketingpro Smarty n00b
Joined: 26 Jun 2017 Posts: 3
|
Posted: Tue Jun 27, 2017 7:39 am Post subject: |
|
|
Thanks AnrDaemon, 2 questions:
1) Why is bad to place business logic into templates?
We are using Smarty in WHMCS and the WHMCS configuration pages explain how to put conditionals in emails, like we are doing, so I guess it's not a bad thing in their opinion. But maybe I'm missing something (maybe in emails are OK but not in other templates).
2) Somebody knows the search function for "does not contain a string"?
I've seen several possible options (like https://stackoverflow.com/questions/21051004/how-to-check-if-a-string-does-not-contain-a-specific-phrase) but they have a structure very different to the one we are using for "does contain" ($service_product_name|strstr:"MAGENTO"). I'm not sure if they are the best option and they would work in Smarty or I have to adapt it somehow (I don't know PHP).
Thanks again! |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Jun 27, 2017 9:13 am Post subject: |
|
|
Your second question answers your first one.
Templates are intended to format the data into a suitable presentation.
They are not designed to choose, which data to format. All the data you want to present should already be readily available, when you are invoking the template engine. |
|
Back to top |
|
marketingpro Smarty n00b
Joined: 26 Jun 2017 Posts: 3
|
Posted: Tue Jun 27, 2017 7:49 pm Post subject: |
|
|
OK, thanks for the explanation AnrDaemon.
Anyone knows the answer to the second question? (the search function for "does not contain a string")
Or at least where should I look or ask?
Thanks! |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
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
|