Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

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