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.

<?php $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=""> </a>

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

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.

Photography for the web

Did someone send you this link? First: Know that it is meant only as a guide. It's not that you can't shoot great photos, this is just to help you capture the best photography possible to be used in marketing. Photos…