We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19579
    • 51 Posts
    I am using the multilingual solution (http://modxcms.com/forums/index.php/topic,29597.msg179898.html#msg179898) for my website. Now I want to add a placeholder inside a chunk so that it automatically loads the chunk corresponding to the right language. My question is why I can’t use a placeholder inside my chunk?

    {{[+language+]_side_menu}}


    I replaced the [+language+] with de language code manually (for example "de") and the contents of the chunk appear on the screen is visible.

    So what am I doing wrong?

    I placed this question in the multilingual thread as well but I think this is a more general question and not specifically related to the multilingual website.

    Thanks in advance for your help!
      • 33337
      • 3,975 Posts
      Zaigham (aka zi) Reply #2, 17 years ago
      Are you talking about placeholder or template variable?

      The placeholder has to be set before it can be used anywhere on the page. So be sure to check if the pre-requisites are present on the page.
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 19579
        • 51 Posts
        Placeholder.

        If I put [+language+] on the page outside the {{ }} it will show it’s value ("de" in my case). So it should be working. But it doesn’t output anything when placed inside the chunk like stated above.
          • 10487 MODX Staff
          • 1,535 Posts
          Garry Nutting Reply #4, 17 years ago
          If I put [+language+] on the page outside the {{ }} it will show it’s value ("de" in my case). So it should be working. But it doesn’t output anything when placed inside the chunk like stated above.
          The reason it doesn’t work when placed inside the chunk is because of the way the document parser works in Evo. Unfortunately, chunks get parsed before the placeholders.

          You could try using a wrapper snippet to do this instead (untested but I think it should work as long as the placeholder is set previously):
          if (array_key_exists('language', $modx->placeholders)) {
              return $modx->getChunk($modx->placeholders['language'] . '_side_menu');
          } else {
              return '';
          }
            Garry Nutting
            Senior Developer
            MODX, LLC

            Email: [email protected]
            Twitter: @garryn
            Web: modx.com
            • 19579
            • 51 Posts
            Thanks! That was the piece of code I needed laugh
              • 15029
              • 35 Posts
              If I may extend this question. I’m trying to do something similar.

              I created a snippet with the original code and including a TV to generate the complete name of the chunk.
              <?php
              if (array_key_exists('language', $modx->placeholders)) {
                 return $modx->getChunk('[*season*]'.'Nav_'.$modx->placeholders['language']);
              } else {
                  return '';
              }
              ?>
              


              ’[*season*]’.’Nav_’.$modx->placeholders[’language’] alone is generating the string I need, "summerNav_gb".
              But the getChunk doesn’t seem to work.
                • 3749
                • 24,544 Posts
                Quote from: JulienT at Oct 27, 2009, 04:55 PM

                If I may extend this question. I’m trying to do something similar.

                I created a snippet with the original code and including a TV to generate the complete name of the chunk.
                <?php
                if (array_key_exists('language', $modx->placeholders)) {
                   return $modx->getChunk('[*season*]'.'Nav_'.$modx->placeholders['language']);
                } else {
                    return '';
                }
                ?>
                


                getChunk won’t translate the tag (although it would be a nice feature). You need to use getTemplateVar() or getTemplateVarOutput() to get the content of the TV first, then use that in the call to getChunk().

                An easier method is to put the TV tag in the call to the snippet as a parameter:

                [!MySnippet? &tvName=`[*season*] !]


                Then in the snippet:

                return $modx->getChunk($tvName . 'Nav_'.$modx->placeholders['language']);


                BTW, I have some code around somewhere for a snippet that returns the name of the current season, which might make the whole TV unnecessary. I could try to find it if you like.


                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  I would like that; I was just thinking of adding such a functionality to an internal intranet site I’ll be working on; no need for an intranet site to be boring, and changing the stylesheet in the manner of CSS Zen Garden according to the seasons would be a nice touch.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 15029
                    • 35 Posts
                    Thank you Bob, it worked great.

                    Thanks for the offer but it won’t be necessary. The season is a page parameter to define the mood of that page and is not based on the real current season. So during the winter you can still have pages with a summer feel.
                      • 3749
                      • 24,544 Posts
                      Quote from: sottwell at Oct 28, 2009, 01:47 AM

                      I would like that; I was just thinking of adding such a functionality to an internal intranet site I’ll be working on; no need for an intranet site to be boring, and changing the stylesheet in the manner of CSS Zen Garden according to the seasons would be a nice touch.

                      Here you go:

                      <?php
                      /* function seasion() -- returns the name of the current season */
                      function season() {
                          $limits=array('/12/21'=>'Winter', '/09/21'=>'Fall', '/06/21'=>'Summer', '/03/21'=>'Spring', '/01/01'=>'Winter');
                      	$adate = date("M d Y");  //set $adate to today
                      
                          foreach ($limits AS $key => $value) {
                      	    
                              $limit=date("Y").$key;
                               if (strtotime($adate)>=strtotime($limit)) {
                      			
                                  return $value;
                              }
                          }
                      }
                      
                      	
                      switch( season() ) {
                      	case "Spring": {
                      		$output = $modx->getChunk("spring");
                      		break;
                      	}
                      	case "Summer": {
                       		$output = $modx->getChunk("summer");
                      		break;
                      	}
                      	case "Fall": {
                       		$output = $modx->getChunk("fall");
                      		break;
                      	}
                      	case "Winter": {
                                      $output = $modx->getChunk("winter");
                      			break;
                      	}
                      	default:		
                      		echo "<h1>   Sorry, there's an Error in Season Specials</h1>";
                      		echo "<h1>   Please notify the webmaster</h1>";
                      	}
                      return $output;
                      ?>
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting