We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33968
    • 863 Posts
    I'm using contexts to handle my multilingual content, with a site_url setting assigned to each context like this:

    {site_url}en/

    Where 'en/' is the subfolder for each language. That's all cool.

    I've used {site_url} to pull in the default site_url system setting as the content needs to be accessed via different domains. The default always reflects the current domain.

    The problem is that the context setting overrides are cached after the first load, so even using an uncached tag in my resources does not make a difference:
    <base href="[[!++site_url]]" />
    


    Any way around this? I've tried using a plugin to alter the site_url OnWebPageInit but this does not affect calls to $modx->makeUrl() or the [ [!++site_url]] tag, or links to the other language contexts [ed. note: okyanet last edited this post 12 years, 6 months ago.]
    • The problem is, if you set a site_url, it will always be that in that context. If you want dynamic site_url, do not set the value in the Context and let the config file determine it from the request headers. Nothing is being cached when you use the non-cacheable tag to place site_url in the base element.
        • 33968
        • 863 Posts
        That's why I got rid of the context settings and tried to add the sub-folder to site_url using a plugin, however it only seems to work for link tags: [ [~5?scheme=`full`]]

        What do you think would be the best way to get the language folders in there, so that makeUrl takes into account the base_url setting (/en/, /fr/, etc)? [ed. note: okyanet last edited this post 12 years, 6 months ago.]
        • Hmmm, I see the problem. I don't think the Contexts as subfolder technique will work at the moment without explicitly setting the site_url for each Context. You might enter a ticket for this as an improvement.
            • 33968
            • 863 Posts
            Thanks Jason, I'll do that.

            Trying to work around it, the problem now is that I cannot get makeUrl to build an absolute link to another context. It always defaults to full.

            Say I am in the /en/ context. The base_url setting is /en/.

            My base tag looks like this:
            <base href="http:/ /www.site.com/en/">
            


            Any absolute link on the page ends up like this:
            /en/link.html
            

            That's fine as it will still go to http://www.site.com/en/link.html

            But if I want to output an absolute link to a page in the /fr/ context - where base_url is set to /fr/, this is what is output:
            http:/ /www.site.com/link.html
            

            Instead of:
            /fr/link.html
            


            I've had a dig into the core code and found that makeUrl() is hard-coded to 'full' url paths when linking to other contexts. Is there a reason for that or am I going about this the wrong way?

            [ed. note: okyanet last edited this post 12 years, 6 months ago.]
              • 33968
              • 863 Posts
              In fact, I wonder if I've uncovered a bug as I've got absolute cross-context links (and as a result, my desired setup) to work by editing the makeUrl() function in both:

              modx.class line 792
              // before - hard-coded scheme?
              $url= $ctx->makeUrl($id, $args, 'full');
              
              // after - accepts function input $scheme
              $url= $ctx->makeUrl($id, $args, $scheme);
              


              modcontext.class line 169
              // before - the if condition is not accepting 'abs' as a valid scheme
              if ($scheme === -1 || $scheme === '' || strpos($scheme, 'abs') !== false) {
                  $scheme= 'full';
              }
              // after
              if ($scheme === -1 || $scheme === '' || strpos($scheme, 'abs') === false) {
                  $scheme= 'full';
              }
              


              Revo 2.1.3-pl [ed. note: okyanet last edited this post 12 years, 6 months ago.]
              • Cross-context links HAVE to be full URLs. Otherwise, they will not work from other Contexts that might be on different domains.
                  • 33968
                  • 863 Posts
                  Sure, but hard-coding that into a key function just based on one possible use of Contexts?

                  It could be easily be rewritten to default to full urls, but allow this to be overridden by the function input. That's roughly what I had expected would occur when I first made a call to makeUrl() - it took me ages to figure out the problem was actually by design.

                  Perhaps a system setting for default_link_scheme would be a good idea?
                  • The setting called link_tag_scheme already provides that default scheme, but the cross-context links force the full URL scheme, regardless of any other settings, by design. What might be better is to introduce link_tag_context_scheme which defaults to full to preserve existing behavior.
                      • 33968
                      • 863 Posts
                      Thanks Jason - sorry I hadn't realised the link_tag_scheme setting existed.

                      link_tag_context_scheme sounds very useful, have put in a feature request here:
                      http://bugs.modx.com/issues/5999