Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smarty If URL Contains

Tags:

php

smarty

x-cart

Using Smarty Tags I'd like to determine if an URL contains a word, something like:

{if $smarty.get.page contains "product.php"} .....

I know contains doesn't exist, but how could I easily go about writing something similar to achieve the above code?

like image 246
99823 Avatar asked Nov 26 '11 19:11

99823


2 Answers

You can use strpos to check if a string has another string inside of it.

$pos = strpos($smarty.get.page, "product.php");

if($pos !== false) {
 // found, do something
}

Except you need to wrap it in {php} and {/php}.

$smarty.get.page translates to $_GET['page'], so you could replace it with the GET variable as well.

like image 182
tekknolagi Avatar answered Nov 03 '22 22:11

tekknolagi


All PHP conditionals and functions are recognized, such as ||, or, &&, and, is_array(), etc.

{if strpos($smarty.get.page, "product.php") !== false}

like image 23
meze Avatar answered Nov 04 '22 00:11

meze