How do I get request uri

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
tralli

How do I get request uri

Post 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'}
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: How do I get request uri

Post by Dr.CSS »

The first one works for me all the time, where are you putting this?...
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: How do I get request uri

Post 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}
NaN

Re: How do I get request uri

Post 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
Locked

Return to “CMSMS Core”