yggdrasil Posted March 13, 2017 Share Posted March 13, 2017 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. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 13, 2017 Share Posted March 13, 2017 But I cannot use it with a smarty variable. ignoring, for now, that {$smarty.server.REQUEST_URI} is a Smarty variable... 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. 0 Quote Link to comment Share on other sites More sharing options...
yggdrasil Posted March 13, 2017 Author Share Posted March 13, 2017 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. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 14, 2017 Share Posted March 14, 2017 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! 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. 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. 0 Quote Link to comment Share on other sites More sharing options...
yggdrasil Posted March 14, 2017 Author Share Posted March 14, 2017 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! yes - so it's a Smarty variable taken from a PHP resource. no, it's all Smarty - the squiggly brackets are the clue. 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. I see, I was confused because you used the PHP enclosure tag in the forums. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 14, 2017 Share Posted March 14, 2017 I see, I was confused because you used the PHP enclosure tag in the forums. I always do that - it's quicker for me to type PHP rather than CODE... plus it adds pretty colours to the output! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.