Advanced Tutorial :: Chunk Versions

Posted on October 01, 2009

The concept of Chunk Versions is a very recent addition to the framework. It can be used for many purposes. The project that it was initially written for, then generalized to be core-framework was one that required multi-lingual support. The issue was for all of the site's content to be available to either french or english viewers without the need to add database fields for each language, because that's messy and repetitive. Unacceptable.

Our solution was to expand on the Chunk class by adding a notion of versions. I'm going to assume that there is a general understanding of Chunks when continuing, although I know you probably don't have an understanding at all. A Primer on Chunks is going to be my next post (promise!).

This notion is best described in a condensed chunk template. I'll describe what this code means in english after you absorb it.

The Code:

{* Chunk Definitions
0 - {$chunks->get("Main Content: type=tinymce; preview=h1,p; versions=english,french"}
*}

{insert_in file=db:site.tpl}
{$chunks->get(0)}
{/insert_in}

In English:

We're saying that in the #mainContent div, we want to insert EITHER an English or French TinyMCE field that by default contains an Header 1 and Paragraph tag.

With the addition of the versions=en,fr on the end of the chunk definition you'll notice that when you go in to administer that page, you'll see 2 TinyMCE boxes nestled right in beside eachother, one labeled English, the other labeled French. See how easy that was? You can also provide the same functionality for authenticated users vs. guests by applying different version labels.

The only caveat here is that you need to be able to pass this module that's using the versions which version you want to use. Luckily we've included a default method for providing this in the URL ex: http://dashboard/(english,french)/*module* (Note: this will change after 2.2 is released, as Routing can take care of this for us.) along with a default SiteConfig variable to set when versions are defined, but none are given.

SiteConfig::get('defaultVersion');
// will return single by default.

You'll notice that some of the default modules are built with versions in mind (ex: Content Module) for your pleasure. So that should let you hit the ground running with Chunk Versions, and you should have multi-language / multi-version pages up and running in no time! Hopefully this brief tutorial was clear as mud.

Comments

No comments on this entry yet
 
back to tips and tricks