We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30226
    • 9 Posts
    Hi,
    New user using a local setup with MAMP. I’ve been following this great tutorial http://codingpad.maryspad.com/2009/03/31/building-a-website-with-modx-for-newbies-part-3-working-with-templates/ but when I add the base url, <base href=”[(site_url)]” /> and preview the page I loose the CSS and image references. Without the base url tag the page renders as expected. It’s got to be something simple but I can’t figure out what it is. Suggestions anyone?

    Thanks,

    Todd
      • 9130
      • 171 Posts
      The base url should match the current installations location, i.e. "http//localhost..." and not the site_url which is probably pointing somewhere else where the css and images are currently not located.
        • 33997
        • 150 Posts
        How are you referring to your css and image files? Are you using absolute references or what?
          "Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
          • 30226
          • 9 Posts
          I’m using relative paths. For example, <link rel="stylesheet" type="text/css" href="assets/templates/somesite/css/styles.css"/>

          Could there be something in the ht.access file that needs adjusting? Could it be a local setting that’s off? It seems so simple but I can’t understand why it’s not working.
            • 33997
            • 150 Posts
            Not to say this would work, but try using the leading forward slash (i.e. /assets/etc). It may be an htaccess issue; I’ve had issues before with the FURLs part of the htaccess file adding in forward slashes.

            Also, take a look at your source code when it works (w/out base href) and also when it doesn’t work (with base href) and see if the links are showing up differently.
              "Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
              • 15175
              • 116 Posts
              Newish user here as well.

              The documentation recommends using:

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

              not

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

              Maybe that is what is causing your issues?
                • 9207 ☆ A M B ☆
                • 2,475 Posts
                j_p -- closing the base tag has to do with your html/xml DOCTYPE; declaring it incorrectly may cause it to parse urls incorrectly given the role of that tag... see if the page validates with W3C’s html validator:
                http://validator.w3.org/

                I think goonz is correct -- I’ve found it’s always less trouble to declare your paths absolutely: use a leading slash to identify exactly which file you are referencing.

                Re the site_url and base_url tags, I would recommend writing a simple Snippet that reads this info from the $_SERVER variable. This makes it easier to port the site over to a new server (e.g. a dev server) and it reads the data from the server, and not from the database.

                <?php
                echo 'http://' . $_SERVER['SERVER_NAME'];
                ?>


                Or, if you’re not going to be changing your URL or server any time soon, just hard-code the name into your templates...


                  • 30226
                  • 9 Posts
                  Thanks everyone. I tried your suggestions but nothing seems to help. I’m starting think I may have a cache issue because when I apply a new template and refresh the page/preview it still shows the previous template, still without css. I’ve triple checked the css path so I don’t know what’s happening.
                    • 22303 MODX Staff
                    • 10,725 Posts
                    Quote from: Everett at Apr 29, 2009, 11:18 PM

                    I think goonz is correct -- I’ve found it’s always less trouble to declare your paths absolutely: use a leading slash to identify exactly which file you are referencing.
                    I think this is a cop out for not coding components correctly TBH. To make portable, reusable components and content in MODx, you should ALWAYS use relative paths. That is the whole purpose of having these settings (base_path, base_url, site_url, etc.).
                      • 3749
                      • 24,544 Posts
                      Quote from: Todd at Apr 30, 2009, 12:25 PM

                      Thanks everyone. I tried your suggestions but nothing seems to help. I’m starting think I may have a cache issue because when I apply a new template and refresh the page/preview it still shows the previous template, still without css. I’ve triple checked the css path so I don’t know what’s happening.

                      Are you clearing both the MODx cache and your browser’s cache?

                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting