views:

123

answers:

2

Ok, say I have a page with the url: URL.com/checkout/completed, how can I setup an if statemet to perform:

<if "This page has url of checkout/completed">

No Content

<else>

Content

</if>

Is there a way? A simple way, my php/smarty-fu lacks.. A lot.

EDIT:

{if $smarty.server.REDIRECT_URL eq 'http://www.euroworker.no/checkout/completed'}
&nbsp;
{else}  
<div id="scrollwrap">   
    <div class="scrollFieldContent"> 

Scrolled content
        </div>

<div class="probetalings">Velg betalingsmåte</div>

{include file="/choosePaymentMethod.tpl"}
</div> 

{/if}

Thanks.

+2  A: 

Have a look at $_SERVER['REQUEST_URI']; and $_SERVER['REDIRECT_URL'];

if($_SERVER['REDIRECT_URL'] == 'checkout/completed') {
   echo 'Some content';
}

in smarty:

{if $smarty.server.REDIRECT_URL eq 'checkout/completed'}
Some content
{/if}

If you don't have REDIRECT_URL set, and use REQUEST_URI, you might want to use strstr instead of typical comparison in case you just want to match that URI while ignoring any additional parameters which might be sent, or go with SCRIPT_NAME as @Pekka suggested:

if(strstr($_SERVER['REQUEST_URI'], 'checkout/completed')) {
   echo 'Some content';
}

EDIT: Try:

{if $smarty.server.REQUEST_URI eq '/checkout/completed'}
karim79
A perfectly fine answer but why `REDIRECT_URL`? It's not set when I call a PHP script in my WAMP setup. Doesn't that only apply when there is a redirect of some sort?
Pekka
@Pekka - my setup has it for some reason. I threw in `REQUEST_URI` additionally in case OP doesn't have `REDIRECT_URL`. Possibly to do with mod_rewrite and my ZF setup.
karim79
Pekka
Sorry guys, but none of this is working :( Will update my question. with the code.
Kyle Sevenoaks
@Kyle Sevenoaks - $smarty.server.REQUEST_URI eq '/checkout/completed'
karim79
Thanks Karim, worked a treat!
Kyle Sevenoaks
+2  A: 

I would prefer SCRIPT_NAME that will return the full request path but not the query string like REQUEST_URI does.

if ($_SERVER["SCRIPT_NAME"] == "/checkout/completed")
 ......
Pekka
I don't understand what you mean by script name. Do I have to attach another script to this?
Kyle Sevenoaks
@Kyle sorry, no, this is about the question which `$_SERVER` variable to use. Those are pre-set variables defined by the web server, available in every script through the `$_SERVER` array. `SCRIPT_NAME` is one of them. There are several very similar variables but they behave differently under different circumstances (and sometimes, server setups). Try the `if(...)` condition as quoted above.
Pekka
Thanks for the explanation, I should go home and learn PHP more. +1
Kyle Sevenoaks