Last active
December 20, 2015 00:09
-
-
Save jkshapiro/6039514 to your computer and use it in GitHub Desktop.
Language toggle button in dotCMS that works with URLMapContent. We include both pieces in header.vtl: "Language selection" toward the top of the file and "Language button" in the place where we want the toggle button to show up. See it implemented at http://immobaker.com. The "$text.get(\"header.notranslation\")" piece is so we can show the user…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- Language selection code begins here--> | |
| ## Determine current language ID | |
| #set($currentLanguageId = $request.session.getAttribute('com.dotmarketing.htmlpage.language')) | |
| #if(!$UtilMethods.isSet($currentLanguageId)) | |
| #set($currentLanguageId = $languagewebapi.getDefaultLanguage().id) | |
| #end | |
| ## Determine new language ID ## Because this site is bilingual, not multilingual, we can simply toggle. | |
| #if($currentLanguageId == 1) | |
| #set($newLanguageId = 3) ## 3 = French | |
| #else | |
| #set($newLanguageId = 1) ## 1 = English | |
| #end | |
| ## Set up the change-language link so it goes to the other-language version of the same page. | |
| ## The method we use to determine the appropriate URL will depend on whether we're using a URL Map | |
| #if($UtilMethods.isSet($request.getAttribute("com.dotmarketing.wiki.contentlet.url"))) | |
| ## This page uses a URL Map | |
| ## The common identifier for all language versions of a URL Map is $URLMapContent.identifier | |
| #foreach($con in $dotcontent.pull("+structureName:News +(conhost:4fc52212-3a33-4b1f-854e-59feb8a03a8f conhost:SYSTEM_HOST) +languageId:$newLanguageId +deleted:false +working:true +identifier:$URLMapContent.identifier",1,'identifier')) | |
| #set($pageURL="/news/$con.urlTitle") | |
| #end | |
| #else | |
| ## This page does not use a URL Map | |
| #set($pageURL=$VTLSERVLET_URI) | |
| #end | |
| ## Prepare the link | |
| #set($classes="language") | |
| #set($otherAttributes="") | |
| #if($currentLanguageId==1) | |
| #set($href="${pageURL}?language_id=3") | |
| #set($langName="Français") | |
| #else | |
| #set($href="${pageURL}?language_id=1") | |
| #set($langName="English") | |
| #end | |
| #if(!$UtilMethods.isSet($pageURL)) | |
| #set($classes="$!{classes} disabled") | |
| #set($href="#") | |
| #set($otherAttributes="rel='tooltip' data-placement='bottom' data-animation='false' title='$text.get(\"header.notranslation\")'") | |
| #end | |
| <!-- Language selection code ends here --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment