EE Insider Tips
Sponsored by Mijingo's EE 2 Screencasts
ExpressionEngine mini-howtos created by the EE Insider community.
Add a dynamic page_uri global variable
For some strange and odd reason, there is no full page_uri global variable built in to EE (that I’ve found at least). You can access each segment with segment variables but there’s not a way to get everything after your domain. We can easily add one by opening our path.php file and adding a global variable there. If you haven’t already created any global variables in your path.php file then it probably has this
$global_vars = array(); // This array must be associative
We can add a variable like this:
$global_vars = array('current_uri'=>$_SERVER['REQUEST_URI']); // This array must be associative
This enables us the use of {current_uri} in our templates. On this page, for example, it would return /tips/add-a-dynamic-page-uri-global-variable/.
One Note: This is using PHP, not EE so it will include anything after the domain. That means “index.php” would be part of it if you aren’t removing it from the URI in some fashion.
Email
Print
Post to Twitter
Post to Delicious
Sean Smith — 12:53 on 04.15.2010
Erik,
thanks for posting this, I can definitely use it.
Erik Reagan — 12:59 on 05.04.2010
That is odd Kyle. How are you generating the URL? Are you using one of EE’s {path} variables?
smartpill — 20:07 on 05.10.2010
Weird. My comment and account disappeared so I didn’t get your reply.
I was using it for the login return, so I had {exp:member:login_form return=”{current_uri}” id=“loggin”}
Kyle
Add Your Comment?
You must have an EE Insider account to post comments on Insider Tips. It's fast, easy and hassle-free.
Sign up now (or login).