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

    i have a page which is in the following format: http://www.example.com/en/example.html?param=parameter where ’param’ is a parameter i have appended myself to the url.

    Now when i switch to another language for example Italian i get sent here: http://www.example.com/it/example.html

    i.e it does not keep the parameter i set, cant the redirection take into account the params aswell so it goes to: http://www.example.com/it/example.html?param=parameter instead?

    Thanks

      • 22851
      • 805 Posts
      Hi Andrew.

      It’s possible to do this. You have to read the submitted GET params and append them to the URLs in the language list. An old forum post describes how a simple snippet can be used to read the GET params and output them as a query string.

      So, you’ll have to edit your YAMS template for your language list to append the query string to the end of the URLs which change the document language. By default the repeat template is:
      <li class="yams_lang_(yams_id)"><a href="(yams_docr)" lang="(yams_tag)" xml:lang="(yams_tag)" dir="(yams_dir)" title="(yams_name_in_(yams_id+))">(yams_name)</a></li>

      so this would become
      <li class="yams_lang_(yams_id)"><a href="(yams_docr)[!QueryParams!]" lang="(yams_tag)" xml:lang="(yams_tag)" dir="(yams_dir)" title="(yams_name_in_(yams_id+))">(yams_name)</a></li>

      where [tt][!QueryParams!][/tt] runs the snippet that grabs the GET params on each page load. Assuming that this in a chunk called [tt]repeattpl[/tt], your language list generating [tt][[YAMS? ...[/tt] snippet call would need to have the parameter [tt]&repeattpl=`repeattpl`[/tt] added to it.

      EDIT: This is not a bug by the way.
      EDIT: There was a duplicate post, so I removed the other one.
        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.
        • 1570
        • 38 Posts
        Thanks PMS, i did just that, below is a snippet i wrote in case others want to use it. I’m pretty sure it won’t work without friendly URLs as i am removing the ’id’ param from the string as well as the ’q’ param, which i dunno what it is exactly i’m guessing its something to do with YAMS.

        Here is the code:

        <?php 
        $query = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);
        $params = array();
        parse_str($query, $params);
        unset($params['q']);
        unset($params['id']);
        
        echo '?'.http_build_query($params); 
        ?>
          • 22851
          • 805 Posts
          Thanks for sharing your code. It’s much neater than mine!

          The q param is to do with MODx and friendly URLs. The .htaccess file strips the ’virtual alias’ from the URL and attaches it as the q query param. MODx analyses the q param to determine the document id. When using YAMS and multilingual aliases, YAMS takes over and figures out the correct document id.
            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.