View previous topic :: View next topic |
Author |
Message |
kepler Smarty Rookie
Joined: 02 Sep 2017 Posts: 5
|
Posted: Sat Sep 02, 2017 2:11 pm Post subject: String not contained in... |
|
|
Hi,
I'm currently making an email template in WHMCS
The idea is to check if the registered domain is a domain or a sub domain of example.com
So, one answer that was given to me was:
Code: |
{if $service_domain|strstr:'.example.com'}
do something
{/if}
|
This works I think IF $service_domain (for instance example.com) isn't preceded by a 'www'
So, how can I solve this?
Can I use:
Code: |
{if ! $service_domain|strstr:'www.example.com'}
{if $service_domain|strstr:'.example.com'}
do something
{/if}
{/if}
|
?...
Can I use the '!' or must I use the 'not'?
Kind regards,
Kepler |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Sat Sep 02, 2017 5:27 pm Post subject: |
|
|
I think it will be very difficult to figure this out using one or two commands.
The variation in what a hostname looks like (after sanitizing) precludes exploding on the periods.
For example, 'flapjacks.co.uk' vs. 'www.pancakes.com'.
You would need to create a function in the template to suss out this variability. |
|
Back to top |
|
kepler Smarty Rookie
Joined: 02 Sep 2017 Posts: 5
|
Posted: Sat Sep 02, 2017 5:38 pm Post subject: Hi |
|
|
Hi
Maybe I've explained me wrong
'example.com' is a fixed variable, a fixed domain. So, the section only must be executed if it matches 'example.com' (it's in the required domain) and not be preceded by 'www' (subdomain only of example.com).
In perl the regex would be something like Code: | /[^w]+\.example\.com$/gi | to the code be executed.
So if my domain is kepler.com, the regex that must be true would be Code: | /[^w]+\.kepler\.com$/gi |
All the other domains would be ignored
Kepler |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Sat Sep 02, 2017 7:55 pm Post subject: |
|
|
If it must match 'example.com' and no other sequence of characters, then:
Code: | {if $service_domain eq 'example.com'}Yes!{/if} | Anything other than this exact string will fail. |
|
Back to top |
|
kepler Smarty Rookie
Joined: 02 Sep 2017 Posts: 5
|
Posted: Sat Sep 02, 2017 8:14 pm Post subject: |
|
|
Hi
No, that's not it.... Imagine that my domain is kepler.com
Subdomains will be, for instance hello.kepler.com, greetings.kepler.com, something.kepler.com, etc...
But www.kepler.com won't.
Kind regards
Kepler |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat Sep 02, 2017 8:28 pm Post subject: Re: String not contained in... |
|
|
kepler wrote: | I'm currently making an email template | does not connect to Quote: | The idea is to check if the registered domain is a domain or a sub domain |
How on earth the message template care about domains?
Fix your logic and don't invent problems where they shouldn't be to begin with. |
|
Back to top |
|
kepler Smarty Rookie
Joined: 02 Sep 2017 Posts: 5
|
Posted: Sat Sep 02, 2017 9:16 pm Post subject: |
|
|
Greetings,
I suposed that in this forum, you should know that in WHMCS emails templates, Smarty is allowed. So you can use conditionals, varibles, etc. to send particular sets of information (or not), formated or even calculated if needed, to the registered user in the registration, invoices, etc.
My bad....
Thanks anyway.
Kind regards
Kepler |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Sat Sep 02, 2017 9:29 pm Post subject: |
|
|
I see that you want to differentiate between a subdomain part, versus when that subdomain part is 'www'.
Maybe:
Code: | {if $service_domain eq 'example.com' or $service_domain eq 'www.example.com'}
www or empty
{else}
other than www, or not example.com
{/if} |
|
|
Back to top |
|
kepler Smarty Rookie
Joined: 02 Sep 2017 Posts: 5
|
Posted: Sat Sep 02, 2017 9:33 pm Post subject: |
|
|
Grretings bsmither
Basically...that's it
I wasn't aware that we could use the operators eq and or like that. It's a little bit like Perl.
Thank you very much - sincerely.
Kind regards,
Kepler |
|
Back to top |
|
|