Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty Conditionals (does not contain)

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
marketingpro
Smarty n00b


Joined: 26 Jun 2017
Posts: 3

PostPosted: Mon Jun 26, 2017 10:11 am    Post subject: Smarty Conditionals (does not contain) Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Jun 26, 2017 11:26 am    Post subject: Reply with quote

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
View user's profile Send private message
marketingpro
Smarty n00b


Joined: 26 Jun 2017
Posts: 3

PostPosted: Tue Jun 27, 2017 7:39 am    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Jun 27, 2017 9:13 am    Post subject: Reply with quote

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
View user's profile Send private message
marketingpro
Smarty n00b


Joined: 26 Jun 2017
Posts: 3

PostPosted: Tue Jun 27, 2017 7:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Jun 28, 2017 7:24 am    Post subject: Reply with quote

Look in http://php.net/manual/en/ref.strings.php
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP