Skip to content

Instantly share code, notes, and snippets.

@jbroadway
Created March 10, 2014 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbroadway/9467440 to your computer and use it in GitHub Desktop.
Save jbroadway/9467440 to your computer and use it in GitHub Desktop.
Rewrite internal links to always include a language prefix (Elefant CMS).
<?php
/**
* Rewrite internal links to always include a language prefix.
* Save this to a handler such as apps/myapp/handlers/langprefix.php
* then edit conf/config.php and add the following to the [Hooks]
* section:
*
* page/render[] = myapp/langprefix
*/
echo preg_replace_callback (
'/a href=(\'|")\/([a-zA-Z0-9_-]{2,}|\1)/',
function ($matches) use ($i18n) {
if (! isset ($i18n->languages[$matches[2]])) {
return 'a href=' . $matches[1] . '/' . $i18n->language . '/' . $matches[2];
}
return 'a href=' . $matches[1] . '/' . $matches[2];
},
$this->data['html']
);
?>
@evan70
Copy link

evan70 commented Mar 10, 2014

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment