Smarty If URL Contains

前端 未结 2 1564
[愿得一人]
[愿得一人] 2021-02-20 04:23

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

2条回答
  •  北恋
    北恋 (楼主)
    2021-02-20 04:50

    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.

提交回复
热议问题