We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    Hi PMS, both are true. The parent page has Resource Type set to Weblink and the used template is multilingual. Thanks for your quick reply!
      • 19328
      • 433 Posts
      I’ve been testing it some more, with a new page, etc. Same thing happens. English works, Dutch doesn’t.
      Some experiments:

      • If I put two different ID’s in the Dutch and English fields, both work. (for example: Dutch: 13, English: 5).
      • If I leave the English field blank, the Dutch one DOES work and the English one redirects to the (Dutch) homepage.
      • If I leave the Dutch field blank this happens in reverse, English works, Dutch redirects to homepage.


      So for some reason it seems to only work for one ID once. I guess because ’content_en’ comes before ’content_nl’ this is the one that gets transformed to an URL. The second language URL seems to ’disappear’ as the Dutch menu item simply links to the base url of the website.
        • 26069
        • 16 Posts
        Does anyone have any experience of ddims solution? What has to be done in order to use it?
          • 22851
          • 805 Posts
          Quote from: michelle84 at Jan 07, 2010, 05:00 PM

          I’ve been testing it some more, with a new page, etc. Same thing happens. English works, Dutch doesn’t.
          Some experiments:

          • If I put two different ID’s in the Dutch and English fields, both work. (for example: Dutch: 13, English: 5).
          • If I leave the English field blank, the Dutch one DOES work and the English one redirects to the (Dutch) homepage.
          • If I leave the Dutch field blank this happens in reverse, English works, Dutch redirects to homepage.

          So for some reason it seems to only work for one ID once. I guess because ’content_en’ comes before ’content_nl’ this is the one that gets transformed to an URL. The second language URL seems to ’disappear’ as the Dutch menu item simply links to the base url of the website.

          Hi Michelle84. I know it’s been ages since you posted this. Very sorry about that. I believe it, but I haven’t been able to reproduce it. It works fine for me, so I’m not sure what to suggest. Perhaps check that your htaccess is up to date. If you are still interested, please check it against Modules>YAMS>Server Config.
            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.
            • 22851
            • 805 Posts
            Quote from: samuel02 at May 06, 2010, 03:46 AM

            Does anyone have any experience of ddims solution? What has to be done in order to use it?
            I haven’t used ddim’s solution myself. Please be aware that as currently written ddim’s snippet will only work for websites using YAMS "root name" mode... but having looked at the snippet it might be possible to create a modified snippet that would work for all YAMS installations in conjunction with my development version of the code from SVN.

            It looks like you would need to do the following to get ddims code to work:

            • Rename your existing FirstChildRedirect snippet so as to keep a backup of it.
            • Create a new snippet called FirstChildRedirect and paste ddims code into it.
            • Call it as follows [tt][!FirstChildRedirect? &mode=`yams`!][/tt]

            Without trying, I can’t be sure where you are supposed to put the snippet call. I would suggest placing it in each multilingual content field of the parent document.
              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.
              • 11867
              • 3 Posts
              I somewhat modified ddim’s approach so it would work for all of YAMSs modes.
              It simply makes use of $YAMS->ConstructUrl().

              <?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.
               * 
               * &yams
               * Whether to use YAMS for the redirct URL construction
               */
              
              $docid = (isset($docid))? $docid: $modx->documentIdentifier;
              $yams = (isset($yams))? true : false;
              
              $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 ($yams) {
              	$yams = YAMS::GetInstance();
              	$firstChildUrl = $yams->ConstructUrl($yams->GetCurrentLangId(), $firstChild['id']);
              }
              return $modx->sendRedirect($firstChildUrl);
              ?>


              So you would call the snippet like so:
              [[FirstChildRedirect? &yams=`1`]]
                • 32541
                • 2 Posts
                Hi, this is my first post here, just wanted to demonstrate my approach. It is useful when the first child is not translated - to avoid redirecting to just the first child and instead redirecting to the first translated child. I’m not a programmer, so I guess it’s not the most elegant solution and I was hoping someone with more skill could make it a bit more elastic (find a better way to filter out untranslated documents) and maybe ditch ditto.

                Hope this helps someone smiley

                <?php
                // Get current language from YAMS
                $yams = YAMS::GetInstance();
                $lang = $yams->GetCurrentLangId();
                
                // Create a Ditto call getting the children of  the current document
                $firstChild = $modx->runSnippet(
                        "Ditto",
                        array(
                            "parents" => $modx->documentIdentifier,
                // Sort the results
                            "orderBy" => "menuindex ASC",
                            "noResults" => " ",
                // Filter them to only display those with a pagetitle set in the current language
                            "filter" => "pagetitle_$lang,,2",
                // Leave just the first one
                            "display" => "1",
                // Get the id of the one selected document
                            "tpl" => "@CODE [+id+]"
                        )
                );
                if(trim($firstChild) != ''){
                // If the Ditto call result is not empty, construct the url
                    $firstChildUrl = $yams->ConstructUrl($lang, $firstChild);
                } else {
                // If the Ditto call result is empty, construct the url to the site start in the current language
                    $firstChildUrl= $yams->ConstructUrl($lang, $modx->config['site_start']);
                }
                // Generate the redirect
                return $modx->sendRedirect($firstChildUrl);
                ?>
                  • 31471
                  • 206 Posts
                  Quote from: michelle84 at Jan 07, 2010, 05:00 PM


                  • If I put two different ID’s in the Dutch and English fields, both work. (for example: Dutch: 13, English: 5).
                  • If I leave the English field blank, the Dutch one DOES work and the English one redirects to the (Dutch) homepage.
                  • If I leave the Dutch field blank this happens in reverse, English works, Dutch redirects to homepage.

                  So for some reason it seems to only work for one ID once.
                  Quote from: PMS at May 10, 2010, 09:28 PM

                  Perhaps check that your htaccess is up to date. If you are still interested, please check it against Modules>YAMS>Server Config.
                  Hi, it’s strange, but I get the same behaviour as michelle84.
                  I checked the htaccess file and it’s like this:
                  # The Friendly URLs part
                  RewriteCond %{REQUEST_FILENAME} !-f
                  RewriteCond %{REQUEST_FILENAME} !-d
                  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]

                  ..but is takes me back to the homepage on the default language, when I use the same ID for the two langs.

                  Any progress or experiment on this issue there yet?
                    • 31471
                    • 206 Posts
                    OK, putting (yams_docr:32) in the content fields, it’s working. (ID=32 in my case.)
                      • 36404
                      • 307 Posts
                      hi,

                      just in case it may be useful, same kind of solution as hauptbenutzer’s one for me except that i simply create a new snippet called yamsFirstChild
                      <?php
                      $docid = (isset($docid))? $docid: $modx->documentIdentifier;
                      
                      $children = $modx->getActiveChildren($docid, 'menuindex', 'ASC');
                      if (!$children === false)
                      {
                          $firstChild = $children[0];
                          $yams = YAMS::GetInstance();
                          $firstChildUrl = $yams->ConstructUrl($yams->GetCurrentLangId(), $firstChild['id']);
                      }
                      else
                      {
                          $firstChildUrl= $modx->makeUrl($modx->config['site_start']);
                      }
                      return $modx->sendRedirect($firstChildUrl);
                      ?>

                      (as you can see, it’s mainly based on the original firstChildRedirect)
                      and call it
                      [[yamsFirstChild]]

                      in the content tv of every language (you can use only once in the original/general MODx content, using for example MODx minimal template set on multilingual if you don’t set Yams to hide redundant fields as i do)

                      this way, i still have firstChildRedirect when if ever i needed it for monolingual page folders and this one for multilingual ones without having to pass any parameter (the advantage for me is not to have to change the page id if the first child went to change

                      have swing
                        réfléchir avant d'agir