<?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); ?>
[[yamsFirstChild]]
Quote from: PMS at May 10, 2010, 09:28 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.
Hi, it’s strange, but I get the same behaviour as michelle84.
Perhaps check that your htaccess is up to date. If you are still interested, please check it against Modules>YAMS>Server Config.
<?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); ?>
<?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); ?>
[[FirstChildRedirect? &yams=`1`]]
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.
Does anyone have any experience of ddims solution? What has to be done in order to use it?
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.