getContext Snippet for MODx Multilingual Site

Below is the snippet code, yup, that's it.  Create a new snippet and call it getContext, done.  MODx API Reference.

$contextKey = $modx->context->key;
return $contextKey;

So how might you use it?  

We used it in getResources templates for "read more" buttons that needed translations. In our case it was "View Bio" but you get the idea.

 <a class="button radius nice" href="">

What this does is, if getContext is = web, that means it's in the defualt context of English; if not we'll assume Spanish. 

There might be other ways to do this, but it worked for us.


Turns out there are better ways.

 Mark Hamstra from the MODx Team commented:

Or, you can use the existing [ [*context_key (or [ [+context_key) tag!
Another third way, would be to put the bits that need to be translated into the lexicons (System > Lexicon Management), and just use the [ [%some.lexicon.key syntax to add in the multilingual text.


Recent Posts

Improving MODX Page Speed for Google

Your website speed is impacting your bottom line , here are a few ways to improve it through browser caching, asynchronous loading of resources and other tips and tricks.

The Status of Liquid Web Cloud Sites Formerly of Rackspace in 2018

We've been a cloudsites customer since our inception, it's had ups and downs, here is what we think about it now.

OG Image Branding with phpThumb and MODX

Some of our clients have wanted to make sure their logo and branding appear in facebook, twitter, or messaging apps when shared. We came up with a clever solution.