We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17930
    • 81 Posts
    When I have multiple Contexts, am I supposed to be able to (and should I) put all my images, css files, etc., for ALL the Contexts into the same directory?
    (Like /www/assets/..)

    If so, how?

    Or am I supposed to do what I am doing now, where the images, css files, etc., for each Context are in that particular Context's directory?
    (Like /www/context2/assets/.. , /www/context3/assets/.. )

    Because sometimes an extra that I am using on another Context needs files that are on the web Context. So instead of pointing to the files at /www/assets/components/.. , it is looking for those files at /www/context2/assets/components/.. , which doesn't exist.

    Does that make sense?
    • Contexts or no, MODx doesn't care where your files are. It's up to you to provide proper paths and URLs to wherever they are. They can even be outside of the web root altogether, in the case of files to be included or used as static resources and elements.
        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
        • 42562
        • 1,145 Posts
        Hi mafokken,

        Are your contexts pointing to different domains (www.mainfirstdomain.com & www.seconddomain.com), hence the www/context2/assets etc?

        If they are on the same domain, no need to worry about the relative references that Extras make to /assets/components/blah/blah right, because it's all heading to the same folder - so no need to have multiple component folders, but you can specify different folders for YOUR OWN custom images and CSS for organisational purposes.

        If the contexts are pointing to entirely different domains (of course on the same server), you can still put YOUR OWN custom images and CSS anywhere you like, just reference them correctly. But you will need to figure a way to tell the Extras to behave properly:


        1. (not a good or convenient procedure) edit the Extras' core to make absolute referencing (i.e, from [[++site_url]]assets/components/... to http://www.mainfirstdomain.com/assets/components/...

        2. (better procedure) In the second domain, the Extras are looking for non-existent stuff by calling [[++site_url]]assets/components/... which translates to http://www.seconddomain.com/assets/components/... All you need do is supply the demand. Duplicate your assets folder and dump the copy in the appropriate place in the seconddomain directory. If you have access, better do this, not with ftp or copy and paste, but straight from your cPanel or server, zip - extract, to make sure everything actually goes across. Don't forget to update the duplicate folders when you perhaps update the originals, by say, updating an Extra.
        3. (dubious method) use .htaccess to reroute calls -- redirects and so on

        I reckon #2 is the best procedure. You follow better web standards: your code won't be making silly calls to various domains but to only one...that is, the fewer external calls the better. You will be at loss though should you, while being in the www.seconddomain.com, ever need anything that comes from www.firstdomain.com/manager. I am thinking of the image and file browser, as accessed say through, TinyMCE in a frontend editor. TiinyMCE will work if its components folder is copied over but that feature will hit a dead page. And copying the Manager folder is a useless thought.

        Perhaps someone will indicate how to kill so many stones with a single bird.
        Cheers
          TinymceWrapper: Complete back/frontend content solution.
          Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
          5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
          • 17930
          • 81 Posts
          First, I hope I'm not being difficult. I'm just trying to understand.

          sottwell,
          The issue I run into and I think I haven't fixed is that some extras are looking for stuff that isn't in that particular Context's folder. Instead the files it needs are only at the web Context.

          Would it be up to every extra developer to make sure it works on other Contexts?

          Or should the extras always be looking at the web Context for their files? (like maybe I haven't set a system setting properly? or maybe the extra wasn't coded properly?)


          donshakespeare,
          Is always having to copy the extras folder (/assets/components/..) over to several different Contexts really the only answer? That is going to be annoying, especially if there are only one or two extras that have updates.


          I just figured out that I should have set the Context settings base_url, site_url, and http_host for the web Context, too. Is that messing up the extras? [ed. note: mafokken last edited this post 11 years, 3 months ago.]
          • The easiest way to fix your issue is doing a url rewrite for the assets folder so your other Context can access it, this is more of an issue with extras not coded to handle multiple Context and not a System Setting or Context Setting issue.

            Have you looked into ContextRouter which supposedly takes care of this type of stuff for you when using multiple Contexts, I haven't messed around with it but Mark Hamstra made it so it should work wink

            Good Luck
              Benjamin Marte
              Interactive Media Developer
              Follow Me on Twitter | Visit my site | Learn MODX
              • 42562
              • 1,145 Posts
              Quote from: mafokken
              Is always having to copy the extras folder (/assets/components/..) over to several different Contexts really the only answer?
              YES! for me, and only the Extras I need.

              I would get a few things clear: your default web Context is attached, as it were, to a local directory, the directory of your main site - www.mainfirstdomain.com. So any physical files that Extras need, by default, are stored there and no where else.
              You don't need to set base_url, site_url, and http_host for the web context (I don't!), if it is going to be using your main site's url or directory.

              Extras that do not have physical files or need to call them will have no problems.
              Extras and their authors don't know what or how many contexts/domains (Top Level Domains) you are going to be using.
              Extras can have an absolute or relative or root-relative linking to their files (CSS, js, images etc)

              1. Absolute = http://www.mainfirstdomain.com/assets/components/greatCIAextra/images/topbar.jpg
              2. Relative = assets/components/greatCIAextra/images/topbar.jpg
              3. Root-Relative = /assets/components/greatCIAextra/images/topbar.jpg

              Maybe you want the Extra developer to use #1, so there won't be any problems? Some do, but then again they don't know your domain name, so they use the common placeholder, [[++site_url]] to replace, say, http://www.mainfirstdomain.com/

              Problem:: [[++site_url]] changes its value when a different context with a different site url is in use, and that's where the Extras start getting discomfubabulated.

              I usually want all my physical files under one domain name, to reduce external calls, that's why I duplicate the assets folder. It really is no biggie, in 4 clicks the whole process is painlessly over. If only one or two Extras get updated, I needn't duplicate the entire assets folder all over again, just those two, or one. Again, this is no trouble to me, still better than having multiple instances of MODx installation.

              What else you can do, until someone else comes with a magical solution

              1. Create your own placeholder [[++firstDomain_url]] = http://www.mainfirstdomain.com/
              2. Edit the core of the Extras (and good luck here), if need be, and replace the [[++site_url]] with yours. So even if the Extra is making calls from your other Contexts, the absolute and fixed link will save matters.
              3. Use .htaccess to automatically rewrite all void links made to http://www.seconddomain.com/assets/components/greatCIAextra/images/topbar.jpg to http://www.mainfirstdomain.com/assets/components/greatCIAextra/images/topbar.jpg. Why, of course you'll need a more general rule.
              In my useless opinion, I reckon, Extras developers should have the path to the Extras' physical files customizable, a variable :
              [[mySlideExtra? &path=`http://www.mainfirstdomain.com/`]] but I can't imagine what hell it'll be to achieve this or what pitfalls this might create.
                TinymceWrapper: Complete back/frontend content solution.
                Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                • 42562
                • 1,145 Posts
                Ah yes, ContextRouter, if you do manage to use it and solve your problem, please let us know. I ran into some problems when I tried once upon a time.

                Maybe there you need to set the http_host for the web context as well.
                  TinymceWrapper: Complete back/frontend content solution.
                  Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                  5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                  • 17930
                  • 81 Posts
                  Quote from: donshakespeare at Jan 23, 2013, 02:11 PM
                  Maybe there you need to set the http_host for the web context as well.

                  I think I may try ContextRouter, but it does say in the opening paragraph of ContextRouter this:

                  "ContextRouter is a simple plug-and-play plugin allowing you to use different contexts, and, based on the http_host context settings you need to set anyway, it routes your front-end requests as required."

                  I'll try to let you know how it works out.
                  • I am using the LangRouter plugin which eliminates the need for .htaccess rules, but this is for subdirectory context rather than subdomain contexts. https://gist.github.com/3812853
                      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
                      • 3749
                      • 24,544 Posts
                      Most (if not all) of my extras that need files have a path property of some kind. It's not that difficult.

                      That said, I think the key piece of information above is that you don't have to set asset_url and assets_path Context Settings. If you don't, you can put everything under the main MODX root directory and all the extras should find things there (in theory).

                        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