Jump to content

Does Smarty support variables inside an smarty?


yggdrasil

Recommended Posts

This is driving me nuts. Example, this works:

 

{if $smarty.server.REQUEST_URI|strstr:'Server'}active{/if}

 

This also works:

 

{if strpos($smarty.server.REQUEST_URI, "Server") !== false}active{/if}

 

But I cannot use it with a smarty variable. Example:

 

{if strpos($smarty.server.REQUEST_URI, "$MyVariable") !== false}active{/if}

 

I tried everything, including:

{if strpos($smarty.server.REQUEST_URI, $Variable) !== false}active{/if}

 

{if strpos($smarty.server.REQUEST_URI, {$Variable}) !== false}active{/if}

 

Double quotes, single quotes, inside or outside parent tags. Nothing. So Smarty can't render variables inside a smarty statement, is this right? PHP can do this, so hence my question.

Link to comment
Share on other sites

But I cannot use it with a smarty variable.

ignoring, for now, that {$smarty.server.REQUEST_URI} is a Smarty variable... :roll:

 

http://www.smarty.net/docsv2/en/language.variables.smarty.tpl

 

{assign brian "http://www.google.com"}
{assign google "google"}
{if strpos($brian, $google) !== false}url contains Google{/if}

forget the first two lines as that just creates two dummy variables, the 3rd line is the one you're after. :idea:

Link to comment
Share on other sites

I'm sorry for being dumb but I don't understand exactly what you tried to explain. Are you saying the code is not Smarty but PHP?

 

I used Request URI in PHP before but I assumption here is that Smarty just reads it from PHP so hence the code has the smarty name on it like $smarty.server.REQUEST_URI

 

What exactly are you saying? I'm not sure what you did in your code, that seems like PHP and you assigned smarty variables for use in PHP?

 

I was trying to avoid PHP and stick to Smarty for learning purposes and to keep things clean in the template.

Link to comment
Share on other sites

I'm sorry for being dumb but I don't understand exactly what you tried to explain. Are you saying the code is not Smarty but PHP?

i'm saying the opposite - the above three lines is 100% Smarty - add it to any template in the client area and watch it work fine! :idea:

 

I used Request URI in PHP before but I assumption here is that Smarty just reads it from PHP so hence the code has the smarty name on it like $smarty.server.REQUEST_URI

yes - so it's a Smarty variable taken from a PHP resource. :)

 

What exactly are you saying? I'm not sure what you did in your code, that seems like PHP and you assigned smarty variables for use in PHP?

no, it's all Smarty - the squiggly brackets are the clue. :-P

 

the first two lines create 2 Smarty variables using the quick Smarty v3 method (btw - it would fail in WHMCS v5, but would certainly work in v7) - I just did that as an easy way to have two variables to see if one is in the other.

 

I was trying to avoid PHP and stick to Smarty for learning purposes and to keep things clean in the template.

the thing you have to remember about Smarty is that it can use PHP functions - so strpos is a PHP function (as is strstr), but you can use them in Smarty. :idea:

Link to comment
Share on other sites

i'm saying the opposite - the above three lines is 100% Smarty - add it to any template in the client area and watch it work fine! :idea:

 

 

yes - so it's a Smarty variable taken from a PHP resource. :)

 

 

no, it's all Smarty - the squiggly brackets are the clue. :-P

 

the first two lines create 2 Smarty variables using the quick Smarty v3 method (btw - it would fail in WHMCS v5, but would certainly work in v7) - I just did that as an easy way to have two variables to see if one is in the other.

 

 

the thing you have to remember about Smarty is that it can use PHP functions - so strpos is a PHP function (as is strstr), but you can use them in Smarty. :idea:

 

I see, I was confused because you used the PHP enclosure tag in the forums.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated