We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9994
    • 133 Posts
    I have a 2 languages website.

    /nl/ and /en/

    I’d like to use the firstchildredirect which works, only when i click on the English navigationbutton i get redirected to the dutch page.

    [!FirstChildRedirect!]

    Any idea’s ?
      Best CMS eva!
      • 22851
      • 805 Posts
      Yes. FirstChildRedirect doesn’t work with YAMS... but there is an alternative approach which does that uses a multilingual weblink. Please see this post.
        YAMS: Yet Another Multilingual Solution for MODx
        YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
        Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
        • 9994
        • 133 Posts
        Ok wrote it but i don’t get it.

        One solution is to make the parent document a weblink that points to the first child.

        How do i do this? Do i have to use Resource Type : weblink or smt? Or redirect to the ID, how do i do this?
          Best CMS eva!
          • 22851
          • 805 Posts
          You can either

          1. create a new weblink, by, say, clicking a on document in the parameter tree to bring up a context menu and then select create weblink

          or, with more recent versions of MODx you can

          2. edit an existing document and change the ResourceType to weblink.

          Please note with option 2 that weblinks treat the content field as a web address or a document id rather than a text field. As a result, when changing the resourcetype to weblink existing document content may be lost.

          Once you have created the weblink, make sure that it is associated with a multilingual template and then place the document id of the first child document in the each content field for each language.
            YAMS: Yet Another Multilingual Solution for MODx
            YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
            Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
            • 7455
            • 2,204 Posts
            Is it not posible to use makeurl and add the yams part to it?

            $url = $modx->makeUrl($id,’’,’&lang=’$_SESSION[’lang’]);

            I do not know if YAMS has a SESSION or cookie or maybe you could use the server url to see if there is a language setting there and grab i using a regular expression.


            Dimmy
              follow me on twitter: @dimmy01
              • 9994
              • 133 Posts
              Well I finally got it lol. (with help of Dimmy)

              Unchecked the ’Use texteditor’ and entered into the (nl / en) contentfields the id number of the page it should redirect to. In my case 17

              #EDIT - had problem with entering the id because i was trying [~17~] that will make it go to the homepage in my case.

                Best CMS eva!
                • 22851
                • 805 Posts
                Yes, that’s it. Thanks Dimmy.
                  YAMS: Yet Another Multilingual Solution for MODx
                  YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                  Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
                  • 6848
                  • 52 Posts
                  Hi,
                  It is actually possible to use FirstChildRedirect with YAMS after small modification in the snippet.
                  The solution is tested with YAMS in root mode.
                  Change the snippet like this:

                  1. Add additional parameter which switches the mode of the snippet (yams or legacy).
                  2. In case of yams mode remove the first slash from $modx->makeUrl
                  3. Call the redirect (in the example it is done by php header() function, but I would expect that $modx->sendRedirect() will work as well

                  <?php
                  /*
                   * @name FirstChildRedirect
                   * @author Jason Coward <[email protected]>
                   * @modified-by Ryan Thrash <[email protected]>
                   * @license Public Domain
                   * @version 1.0
                   * 
                   * This snippet redirects to the first child document of a folder in which this
                   * snippet is included within the content (e.g. [!FirstChildRedirect!]).  This
                   * allows MODx folders to emulate the behavior of real folders since MODx
                   * usually treats folders as actual documents with their own content.
                   * 
                   * Modified to make Doc ID a required parameter... now defaults to the current 
                   * Page/Folder you call the snippet from.
                   * 
                   * &docid=`12` 
                   * Use the docid parameter to have this snippet redirect to the
                   * first child document of the specified document.
                   */
                  $docid = (isset($docid))? $docid: $modx->documentIdentifier;
                  $mode = (isset($mode))? $mode :"";
                  $children= $modx->getActiveChildren($docid, 'menuindex', 'ASC');
                  if (!$children === false) {
                      $firstChild= $children[0];
                      $firstChildUrl= $modx->makeUrl($firstChild['id']);
                  } else {
                      $firstChildUrl= $modx->makeUrl($modx->config['site_start']);
                  }
                  if ($mode=="yams"){
                      header( 'Location: ' . substr($firstChildUrl,1) , TRUE, 303);
                      return;
                  }
                  else {
                    return $modx->sendRedirect($firstChildUrl);
                  }
                  ?>
                  


                  To state again - this is tested only with root mode of yams and modx in the root of the web.
                    • 19328
                    • 433 Posts
                    Hi there! I’m building a website with YAMS and I think it’s great! I just can’t get the weblink (as replacement for firstChildRedirect) to work. I think I’ve followed the instructions to the letter but maybe someone knows what I’m doing wrong.

                    I’ve got two languages (nl and en, Dutch and English). On the parent page that needs to redirect to the first child, I’ve turned off the html editor, and I’ve put the ID of the first child (13) in both the content fields for nl and en. I save the page and this is what happens: it does work for the English link, but the Dutch one links to the homepage instead of the first child.

                    I’m using YAMS in root name mode. The Dutch version is without a language in the path, the English version has the path mysite.nl/en/

                    (BTW I also tried the adjusted version of FirstChildRedirect but the English link redirects to Dutch.)
                      • 22851
                      • 805 Posts
                      The parent page needs to be given the Resource Type "Weblink" instead of "Web Page". With MODx 1.0.2 this can be done from the Settings tab of the document. Please can you confirm that that is the case? Also, the parent page (weblink) also needs to be associated with a multilingual template. Is that true?

                      Cheers.
                        YAMS: Yet Another Multilingual Solution for MODx
                        YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                        Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.