We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13735
    • 62 Posts
    Hey,

    Long ago I created a joomla template and there was a way to get the url of the site. This function simply returns "http://www.example.com/". Is there a function similar to this in modx to? I couldn’t find a system setting for this and I always use absolute paths to avoid trouble. So how? laugh

    regards,
    JB
      • 28215
      • 4,149 Posts
      Quote from: jbjoe at Mar 03, 2010, 05:14 PM

      Long ago I created a joomla template and there was a way to get the url of the site. This function simply returns "http://www.example.com/". Is there a function similar to this in modx to? I couldn’t find a system setting for this and I always use absolute paths to avoid trouble. So how? laugh

      In MODx Tags:

      [[++site_url]]


      In PHP:

      $modx->getOption('site_url');


      Note that base_url is not equal to site_url.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
      • In Revolution, site_url is the setting you want, and this can be overridden (and hardcoded if you want) by Context. Otherwise, it is automatically determined based on the host name requested by the client and/or the web server/php configuration.

        In content:
        [[!++site_url]] <!-- This returns the site_url setting and the ! indicates this is not cacheable -->


        In code:
        <?php
        /* gets the site_url setting */
        $site_url = $modx->getOption('site_url');
        ?>


        Generally, the only place you ever need this is in the HEAD of your MODx Template( s ), e.g.:
        <head>
            <base href="[[!++site_url]]" />
            ....
        </head>
        

        That way you can use relative paths in all your content and it will always respect the absolute location defined by your site_url, regardless of where/how it is deployed.
          • 13735
          • 62 Posts
          Thanks for these great replies!

          regards,
          JB