We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51003
    • 8 Posts
    Hi everyone!

    I have a rather difficult setup for a client of mine. The client has two domains but much of the content overlaps, only a very small part of the website needs to be different on one of the websites.

    So basically this is the setup I was thinking of so far:

    domain.de -> context web
    domain.at -> context web-at -(not found)-> context web

    Using the Gateway plugin to connect the two domains to their contexts, will solve the first part of the problem.

    I am however unsure how to get the modx to deliver the resource(site) from the web context if it is not present in the web-at context. also how should i configure the wayfinder plugin so it will always display all the sites from web context, but still link to the web-at site in case it does exist.

    Also there are some chunks which need to be different depending on the domain, no matter whether the site is stored in web or web-at context.

    A translation plugin would probably be part of the solution, however I have no idea how to set it up correctly.

    Hope someone has an idea or experience setting this up.

    Thanks a lot
    Jan

    PS: I am aware it is a bad practice to have the same content on multiple sites SEO-wise, but the client cannot be swayed...

    This question has been answered by m.engel. See the first response.

      • 28120
      • 380 Posts
      The following will not solve all your problems but it's very useful

      [[*context_key]]

      the *context_key will be either 'web' or 'at' (using your example)

      In your templates use

      [[$chunk1_[[*context_key]]]]

      You then to to create the appropriate chunks

      chunk1_web
      chunk1_at
        • 9266 ☆ A M B ☆
        • 77 Posts
        Jan_salem,

        Based on what I am see you could most like get some of the leg work done by using Babel. https://rtfm.modx.com/extras/revo/babel The setup is pre-straight forward, and will help with the domain issue. I would give that a try.
          • 51003
          • 8 Posts
          thanks a lot for the replies, I have looked further into the matter.

          I will use babel and one gateway plugin, however i will need to write my own plugin in order to switch between the contexts properly.

          Therefore I would like to know how i can use a friendly url with the modx object to check if the url exists within the current context.

          To clarify I am looking for a solution within the modx API that gets me a resource from a given friendly url. Something along the following lines:

          If(!$modx->getObject('modResource', array("friendlyUrl" => $someFriendlyURL) {
              $modx->switchContext("web");
              $modx->sendForward($someFriendlyURL);
          }
          //else just process normaly
          


          i have tried to search for a similar problem, but was unable to find it, hope i wasn't just blind smiley
          • discuss.answer
            • 40706
            • 128 Posts
            We have an Customer wich had an similar but much further Integration. He uses 4 Websites in 9 Languages which have 90% the same Content.

            Manual Version
            Simply create lots of Symlinks in the at context and replace the symlinks with documents where the content differs


            PHP Version
            You have to create an Plugin on "OnPageNotFound"
            which does something like following. It replaces the active resource to another one, in another context. Maybe $modx->sendForward() is also an option for you. In theses cases i usaly do this manually to manipulate the caching and other things.

            beware its very "raw" and just copied & coded here inside for demonstration.

            	
                            if($modx->context->key != 'at') return '';
            
            		$resourceId = $modx->findResource($_GET['q'], 'web');
                            if(!$resourceId) return '';
            
                            // Maybe in your case just forward...
                            $modx->sendForward($resourceId);
                            // otherwise...
                            $modx->resource = $modx->request->getResource('id', $resourceId, array('forward' => true));
            		if ($modx->resource) {
            				$modx->resource->_fields['context_key'] = $modx->context->key;
            				$modx->resource->_context_key = $modx->context->key;
            				$modx->resource->set('context_key', $modx->context->key);
            				$modx->elementCache                     = array();
            
            				$modx->resourceIdentifier = $modx->resource->get('id');
            				$modx->resourceMethod     = 'id';
            				$modx->request->prepareResponse();
            				exit();
            		}
            



            Wayfiner has an context setting, just use this to always create an Menu for "web"

            The Routing to the at-context-if-exists can handled via an Snippet like this:

            BabelId

            <?php
            $babel = $modx->getService('babel','Babel',$modx->getOption('babel.core_path',null,$modx->getOption('core_path').'components/babel/').'model/babel/',$scriptProperties);
            
            if (!($babel instanceof Babel)) return;
            
            /* be sure babel TV is loaded */
            if(!$babel->babelTv) return;
            
            /* get snippet properties */
            $resourceId = $modx->resource->get('id');
            if(!empty($scriptProperties['input'])) {
            	$resourceId = intval($modx->getOption('input',$scriptProperties,$resourceId));
            }
            
            $contextKey = $modx->context->get('key');
            if(!empty($scriptProperties['options'])) {
            	$contextKey =$modx->getOption('options',$scriptProperties,$contextKey);
            }
            
            
            /* determine id of tranlated resource */
            $linkedResources = $babel->getLinkedResources($resourceId);
            
            // published check
            
            if($linkedResources[$contextKey])
            	return $linkedResources[$contextKey];
            if($linkedResources["en"])
            	return $linkedResources["en"];
            if($linkedResources["web"])
            	return $linkedResources["web"];
            
            return $resourceId;


            And called inside the Wayfinder templates as output Filter [[~[[+id:BabelId]]]
              • 51003
              • 8 Posts
              Thanks a lot for the code snippets, I managed to get it to work.
              Although it is probably an rather ugly hack because I am switching between contexts in order to get the correct resource.

              Once again thank you for the quick help.
              Greetings from germany,
              Jan