ExpressionEngine CMS
Open, Free, Amazing


This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Is there a global template variable for the current url

May 04, 2010 3:57pm

Subscribe [5]
  • #1 / May 04, 2010 3:57pm

    Flying Fish's avatar

    Flying Fish

    119 posts

    I’ve been looking at the docs and I see how to get all of the url segments as a variable.

    I also know how to get the site_url by itself.

    but is there any kind of global var for the current page or url?

    I know I could get it with CI or pure PHP, but I was sort of hoping there was an EE tag for it already.

  • #2 / May 04, 2010 5:53pm

    JasonLeeLab's avatar


    53 posts

    Unfortunately there isn’t a variable for the current url.

    If you know how many segments you’ll be working with you can do something like this:


    If the number of segments won’t always be the same you can add conditionals:

    {site_url}/{segment_1}/{if segment_2}{segment_2}/{/if}

    I do agree that it would be nice to have a variable that does all this for you.

  • #3 / May 04, 2010 5:57pm

    Flying Fish's avatar

    Flying Fish

    119 posts

    thanks for reply!

  • #4 / May 05, 2010 2:50pm

    Flying Fish's avatar

    Flying Fish

    119 posts

    I’m throwing out this little plugin as a quickie fix

    so you can effectively use these tags in your template
    {exp:get_url:current_url} {exp:get_url:uri_string}

    critiques are very welcome

    if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    $plugin_info = array(
        'pi_name' => 'Get Url',
        'pi_version' => '1.0',
        'pi_author' => 'Flying Fish',
        'pi_author_url' => '',
        'pi_description' => 'Used to return the current all in full or all segments.',
        'pi_usage' => Get_url::usage()
    class Get_url {
        function Get_url()
            $this->EE =& get_instance();
        function uri_string()
            return $this->EE->uri->uri_string();
        function current_url()
            return $this->EE->functions->fetch_current_uri();
        function usage()
            return 'Incredibly simple plugin to return full url of all segments.';
    /* End of file pi.plugin_name.php */ 
    /* Location: ./system/expressionengine/third_party/get_url/pi.get_url.php */
  • #5 / May 05, 2010 4:21pm

    imjared's avatar


    23 posts

    good idea. unfortunately, when i upload the plugin, i get an error when i attempt to access my plugin manager: “No direct script access allowed”

  • #6 / May 05, 2010 4:31pm

    Flying Fish's avatar

    Flying Fish

    119 posts

    imjared, I’m working on the latest build of 2.0.2, would you happen to be on 1.6.9?

    the folder goes here

    I’ll update the attached file so that it comes in zipped in the get_url folder

  • #7 / May 05, 2010 4:37pm

    imjared's avatar


    23 posts

    that would do it, yes i am.

  • #8 / May 05, 2010 4:46pm

    Flying Fish's avatar

    Flying Fish

    119 posts

    Ya I’m using some CI shortcuts to grab pieces of the url (codeigniter makes it so easy)

    there has to be a pretty straightforward way to do it in 1.6.9 too, will have to look at that another time

  • #9 / May 05, 2010 4:55pm

    Wouter Vervloet's avatar

    Wouter Vervloet

    758 posts

    I don’t know if this works in EE2, but in 1.6 I’ve always used


    It looks a bit weird, but it works! EE itself checks to see if a segment has been set and generates a url from it.

  • #10 / May 06, 2015 5:14am

    {current_url} seems to work for me in EE 2.9.0

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases