Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get current URL using smarty

Tags:

smarty

How to get URL using Smarty similar to window.location in JavaScript ?

I did this

{$smarty.server.PHP_SELF}  

but it's not working.

like image 206
user1187 Avatar asked Oct 30 '12 12:10

user1187


Video Answer


2 Answers

This is controller code :

<?php require_once('libs/Smarty.class.php'); $smarty = new Smarty(); if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {     $pro = 'https'; } else {     $pro = 'http'; } $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); $current_url =  $pro."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];  $smarty->assign("current_url",$current_url); $smarty->display('index.tpl');  ?> 

You can display variable in index.tpl template file :

<html>     <head>         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />         <title>Title</title>     </head>     <body>          {$current_url}      </body> </html> 
like image 23
senthilbp Avatar answered Sep 19 '22 07:09

senthilbp


You can use this, too.

{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI} 
like image 112
sertaconay Avatar answered Sep 21 '22 07:09

sertaconay