We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28584
    • 27 Posts
    Hi all
    Im a newb to modx so go easy with me.
    I’d like to know the easiest way to use php global variables/constants within a template?

    my specific issue is with the minimal default template which creates a

    <base href="[(site_url)]" />

    based on the value set within the administrator/at install time I assume?

    I think this is an odd thing to do as each client may browse to your site through differing urls
    (due to, hostfile over ride, clustering, dev to live work)
    Id suggest that the base url for each page should be based on

    $_SERVER[’SERVER_NAME’]

    thanks in advance for your advice on how to access these within a template.
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: stewski at Sep 11, 2006, 09:26 AM

      Hi all
      Im a newb to modx so go easy with me.
      I’d like to know the easiest way to use php global variables/constants within a template?

      my specific issue is with the minimal default template which creates a

      <base href="[(site_url)]" />

      based on the value set within the administrator/at install time I assume?

      I think this is an odd thing to do as each client may browse to your site through differing urls
      (due to, hostfile over ride, clustering, dev to live work)
      Id suggest that the base url for each page should be based on

      $_SERVER[’SERVER_NAME’]

      thanks in advance for your advice on how to access these within a template.

      It is based on this value; and if all you want is this value, then go right ahead and create a Snippet that simply returns $_SERVER[’SERVER_NAME’] and use that; i.e. <base href="[[GlobalServerName]]" />.
        • 7923
        • 4,213 Posts
        You can look at manager/includes/config.inc.php to see how site_url and base_url variables are constructed.


          "He can have a lollipop any time he wants to. That's what it means to be a programmer."
          • 28584
          • 27 Posts
          curious looking at config.inc.php
          suggests that if base_path or base_url ==""
          then it will automagically assign them based on script_name (which is pretty much what Im suggesting).
          However on my install its using localhost no matter how I access the site (via IP or virtual hostname)
          odd odd odd.

          Cheers peeps for the pointers, is there somewhere I could’ve accidentaly set my base/site url so that config.inc.php doesnt over ride it?

          wouldnt it make sense to ship modx with snippets that mirror most of phps constants, most of your users will be php savvey, is it because we want to promote a different way of doing things or just a yeah maybe we should do that someday?
            • 7923
            • 4,213 Posts
            What do you have in your apache httpd.conf as ServerName? I’m guessing localhost.

            Quote from: stewski at Sep 11, 2006, 10:06 AM

            wouldnt it make sense to ship modx with snippets that mirror most of phps constants, most of your users will be php savvey, is it because we want to promote a different way of doing things or just a yeah maybe we should do that someday?
            I’m thinking just the opposite. MODx should be released just as the core framework as light as possible and all not essential resources should be in resource repository available for download (some client preferably in modx to download and install the resource straight from modx manager). In future, it’s possible that you will see multiple different modx "distros" available, like developers modx, bloggers modx, gallerists modx... etc. where all are built onto core modx framework, but may have some additional resources on top of that.. like linux distros.


              "He can have a lollipop any time he wants to. That's what it means to be a programmer."
              • 28584
              • 27 Posts
              Quote from: doze at Sep 11, 2006, 10:32 AM

              What do you have in your apache httpd.conf as ServerName? I’m guessing localhost.

              Quote from: stewski at Sep 11, 2006, 10:06 AM

              wouldnt it make sense to ship modx with snippets that mirror most of phps constants, most of your users will be php savvey, is it because we want to promote a different way of doing things or just a yeah maybe we should do that someday?
              I’m thinking just the opposite. MODx should be released just as the core framework as light as possible and all not essential resources should be in resource repository available for download (some client preferably in modx to download and install the resource straight from modx manager). In future, it’s possible that you will see multiple different modx "distros" available, like developers modx, bloggers modx, gallerists modx... etc. where all are built onto core modx framework, but may have some additional resources on top of that.. like linux distros.

              yep I can see that is sensible indeed, if I work on snippets to mirror php values/constants how can we share them?

              any idea on why this install may be locking base/site url to localhost?
                • 28584
                • 27 Posts
                OK decided the tidiest/quickest on this is to remove base url from my templates.
                if you think there are any issues with doing this let me know...
                  • 7923
                  • 4,213 Posts
                  Quote from: stewski at Sep 11, 2006, 10:37 AM

                  yep I can see that is sensible indeed, if I work on snippets to mirror php values/constants how can we share them?
                  Put it in the resource repository, while it’s in developement, you can discuss about it here and get testers etc..

                  Quote from: stewski at Sep 11, 2006, 10:37 AM

                  any idea on why this install may be locking base/site url to localhost?
                  It takes the site url from $_SERVER[’HTTP_HOST’] (I was wrong in the reply before, I thougt it used $_SERVER[’SERVER_NAME’] what would of come from apache http.conf)

                  $_SERVER[’HTTP_HOST’] comes from the current request Host: header, so it should take what you have typed in your browser. I just tried it my self and for me [(site_url)] prints "http://localhost.." if I access the site using localhost and "http://85.157..." if I access via IP.


                    "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                    • 28584
                    • 27 Posts
                    Quote from: doze at Sep 11, 2006, 02:27 PM

                    Quote from: stewski at Sep 11, 2006, 10:37 AM

                    yep I can see that is sensible indeed, if I work on snippets to mirror php values/constants how can we share them?
                    Put it in the resource repository, while it’s in developement, you can discuss about it here and get testers etc..

                    Quote from: stewski at Sep 11, 2006, 10:37 AM

                    any idea on why this install may be locking base/site url to localhost?
                    It takes the site url from $_SERVER[’HTTP_HOST’] (I was wrong in the reply before, I thougt it used $_SERVER[’SERVER_NAME’] what would of come from apache http.conf)

                    $_SERVER[’HTTP_HOST’] comes from the current request Host: header, so it should take what you have typed in your browser. I just tried it my self and for me [(site_url)] prints "http://localhost.." if I access the site using localhost and "http://85.157..." if I access via IP.

                    thanks for the tips/directions.

                    on my install [(site_url)] is evaluating to localhost regardless of whats in the header/address bar on the client side.
                    V odd.
                    in my /manager/includes/config.inc.php it only appears to evaluate site_url based on http_host IF base_url or base_path are ""
                    is there anywhere that these could have both been already set so as to avoid it picking the header info and locking me to localhost?

                    thanks again...
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      check the config.inc.php file.
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org