Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

String not contained in...

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
kepler
Smarty Rookie


Joined: 02 Sep 2017
Posts: 5

PostPosted: Sat Sep 02, 2017 2:11 pm    Post subject: String not contained in... Reply with quote

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


Joined: 20 Dec 2011
Posts: 267
Location: West Coast

PostPosted: Sat Sep 02, 2017 5:27 pm    Post subject: Reply with quote

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


Joined: 02 Sep 2017
Posts: 5

PostPosted: Sat Sep 02, 2017 5:38 pm    Post subject: Hi Reply with quote

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


Joined: 20 Dec 2011
Posts: 267
Location: West Coast

PostPosted: Sat Sep 02, 2017 7:55 pm    Post subject: Reply with quote

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


Joined: 02 Sep 2017
Posts: 5

PostPosted: Sat Sep 02, 2017 8:14 pm    Post subject: Reply with quote

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


Joined: 03 Dec 2012
Posts: 1633

PostPosted: Sat Sep 02, 2017 8:28 pm    Post subject: Re: String not contained in... Reply with quote

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


Joined: 02 Sep 2017
Posts: 5

PostPosted: Sat Sep 02, 2017 9:16 pm    Post subject: Reply with quote

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


Joined: 20 Dec 2011
Posts: 267
Location: West Coast

PostPosted: Sat Sep 02, 2017 9:29 pm    Post subject: Reply with quote

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


Joined: 02 Sep 2017
Posts: 5

PostPosted: Sat Sep 02, 2017 9:33 pm    Post subject: Reply with quote

Grretings bsmither

Basically...that's it Smile

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    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