Page 1 of 1

How do I get request uri

Posted: Thu Dec 02, 2010 12:00 pm
by tralli
I need to get the url and test if it is '/index.php' or '/index.php?var=something' I tried doing something like this:

Code: Select all

{if $page_alias == 'home'}
but it returns true regardless of the parameters I want it to return true only if the url is /index.php. So I figured I could make a tag called current_url with this code

Code: Select all

echo trim($_SERVER['REQUEST_URI']);
it returns the string I want but how do I test it in my template? I can't write

Code: Select all

{if {current_url} == '/index.php'}

Re: How do I get request uri

Posted: Thu Dec 02, 2010 10:03 pm
by Dr.CSS
The first one works for me all the time, where are you putting this?...

Re: How do I get request uri

Posted: Sat Dec 04, 2010 7:12 pm
by jmcgin51
tralli wrote: I need to get the url and test if it is '/index.php' or '/index.php?var=something' I tried doing something like this:

Code: Select all

{if $page_alias == 'home'}
but it returns true regardless of the parameters I want it to return true only if the url is /index.php. So I figured I could make a tag called current_url with this code

Code: Select all

echo trim($_SERVER['REQUEST_URI']);
it returns the string I want but how do I test it in my template? I can't write

Code: Select all

{if {current_url} == '/index.php'}
The first code snippet just tests for the page alias, not the URL or any GET variables.

to use your UDT in a template, you first need to capture the output

so
{capture assign='url'}{current_url}{/capture}
{if $url == '/index.php'}
do this
{/if}

Re: How do I get request uri

Posted: Sat Dec 04, 2010 7:46 pm
by NaN
No need for a UDT.
You cann REQUEST_URI using smarty syntax:

Code: Select all


{$smarty.server.REQUEST_URI}

http://www.smarty.net/forums/viewtopic. ... 241fcc0af1