WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: lash on February 23, 2011, 01:39:27 PM

Title: Droplet: Language Switcher URL
Post by: lash on February 23, 2011, 01:39:27 PM
Hi... i build a little droplet based on the Language Switcher Snippet. The code is much shorter but it uses the same technique. So the requirements are the same. The menu trees of the different languages have to be the same. If there's no corresponding page use a dummy page (with visibility set to hidden or none). In this case the language root is returned.
You also have to set the language attribute of all pages correctly. Normally you only have to do this for the root entries (EN, DE, ...), on all other pages it is automatically set to its parent value.

The droplet only returns the URL, so you have to build the links yourself!

Code: [Select]
<?php

global $database$wb;

$url WB_URL.$_SERVER[&#39;PHP_SELF&#39;];

if (strtolower(LANGUAGE) != strtolower($lang)) {

// get additional page info
$sql "SELECT position, menu FROM ".TABLE_PREFIX."pages WHERE page_id = ".PAGE_ID;
$get_content $database->query($sql);
$page_info $get_content->fetchRow();

// get link
$sql = "SELECT link, visibility FROM ".TABLE_PREFIX."pages ";
$sql .= "WHERE language = &#39;".strtoupper($lang)."&#39; AND position = ".$page_info[&#39;position&#39;]." ";
$sql .= "AND level = ".LEVEL." AND menu = ".$page_info[&#39;menu&#39;];

$get_content $database->query($sql);
$content $get_content->fetchRow();

if ($content && $content[&#39;visibility&#39;] === &#39;public&#39;) {
$url WB_URL.PAGES_DIRECTORY.$content[&#39;link&#39;].PAGE_EXTENSION;
}
else {
$url WB_URL.PAGES_DIRECTORY.&#39;/&#39;.strtolower($lang).PAGE_EXTENSION;
}
}
return 
$url;

?>


Just insert the code (without <?php ... ?>) into the droplet creator and call it with [[dropletname?lang=(code)]];