Skip to content

Instantly share code, notes, and snippets.

@ideesimple
Created January 17, 2011 11:56
Show Gist options
  • Save ideesimple/782763 to your computer and use it in GitHub Desktop.
Save ideesimple/782763 to your computer and use it in GitHub Desktop.
site bilingue
créer le context avec
http://www.class-zec.com/en/blog/2011/seo-friendly-multilingual-websites-with-modx-and-babel.html
site_url = {base_url}fr/
cultureKey = fr
site_start = 20 // rajouter quand babel sera installé
rajouter le nouveau context pour les utilisateurs anonyme
Security -> Access controls
modifier le .htaccess
RewriteRule ^(fr|en)?(\/)?(.*)$ index.php?c=$1&q=$3 [L,QSA]
mettre en place les url simple
installer le package translit pour supprimer les accents des alias
créer un plugin pour switcher le bon contexte avec l'événement OnHandleRequest
if ( $modx->context->get( 'key' ) != 'mgr') {
/**
* grab the current context from the request "c" parameter (or context_param_alias from system settings)
* the alternative .htaccess friendly URL rewrite rule must be activated
*/
$cntxt_param = $modx->getOption('context_param_alias', null, 'c');
if ( isset( $_REQUEST[$cntxt_param] ) && $_REQUEST[$cntxt_param] != '' ) {
switch ( $_REQUEST[$cntxt_param] ) {
case 'fr':
//switch the context
$modx->switchContext('web');
//set the cultureKey
$modx->setOption('cultureKey', 'fr');
break;
case 'en':
$modx->switchContext('Anglais');
$modx->setOption('cultureKey', 'en');
break;
default:
// Set the default language/context here
$modx->switchContext('web');
$modx->setOption('cultureKey', 'fr');
break;
}
}
}
To achieve this, simply reference all asset additions using the [[++base_url]] system setting. That is, in a template or chunck element, reference you assets as follow:
CODE:
<link rel="stylesheet" href="[[++base_url]]assets/templates/css/myrules.css" type="text/css" media="screen" />
<script type="text/javascript" src="[[++base_url]]assets/libs/myjscode.js"></script>
<img src="[[++base_url]]assets/templates/images/myimage.png" alt="description" />
<!-- or from a TV -->
<div class="img_container" style="background: url([[++base_url]][[*tv_image]]) no-repeat"></div>
When it comes to snippets (embedding code in the head part for example), reference your assets using:
CODE:
$modx->regClientStartupScript( $modx->getOption('base_url') . 'assets/libs/myjscode.js' );
installer wayfinder et penser à mettre l'option &fullLink=`TRUE
[[!Wayfinder? &startId=`0` &fullLink=`TRUE`]]
installer babel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment