Context-module (Drupal)
De context-module is een alternatief voor het gebruik van blocks. Onder andere is het reken-efficiënter.
Inleiding
Deze inleiding vind ik zo goed, dat ik 'm in z'n geheel heb overgenomen [1].
Vraag
I see drupalers mention Context module everywhere. I went through the project page, also watched some slides & videos about the Context module. I understand it can group together different related pages conceptually (such as global context, user profile context, blog context and so on). But how can we actually benefit from a context we created? For example: It allows us to assign a block for a context, but this can be easily done by setting Block Visibility for different blocks. I am not able to uncover of beauty of Context module. Can you suggest some use cases of the Context module? What makes it so popular?
Antwoord
The Context module is the blocks system on crack, basically. If you have more specific needs for elements on a page, the blocks system very quickly becomes limiting. Of course, if you haven't run into these issues, you might be fine not using the Context module. There is another reason, however, to use Context module, even if you don't really need most of the features. If your site makes heavy use of Blocks, Drupal's core rendering system, at least in Drupal 6, is quite inefficient. Here's why: Any block that is configured to be displayed in a specific region will be rendered on every page, even if it's not visible. So if you put 50 blocks in the 'sidebar' region, but only two are visible on a particular page, Drupal will still render all blocks. From the book 'Drupal's Building Blocks': "When Drupal is preparing a page, it renders every single block for display and then checks whether the block will be displayed on the page that is being rendered. If the block is being used, the rendered block is pushed into the page template (Figure 12-1).This logic is both upside down and inefficient." From what I understand, Context solves this issues. Furthermore, if you use it you're likely to start using its more advanced features, and you probably won't regret moving away from the vanilla blocks system. (The aforementioned quote is in a chapter on the Panels module, which is somewhat similar - but more powerful - than Context. If you run into limitations of Context, or don't like its approach, be sure to check that module out as well!)
Blocks & meertaligheid
Vertaalde blocks zijn moeiteloos te combineren met taal-afhankelijke contexts:
- In meertalige sites is het mogelijk om blocks te vertalen. Die vertalingen verschijnen echter niet als aparte blocks in het blocks-overzicht
- Indien je een taalafhankelijke context defineert (bv. Duitstalige frontpage), en je plaatst het oorspronkelijke block (in dit geval een Nederlandstalig block), dan verschijnt vanzelf de Engelstalige versie.
Waarom dit zo handig is: Het blocks-overzicht wordt al snel een onoverzicht. Daarom handig dat vertaalde blocks niet apart vermeld worden, maar ook handig dat Contexts daar soepeltjes op voortborduurt.
Context & meertaligheid
Om het onderwerp hiervoor te vervolgen: Aangezien blocks en nodes automatisch van taal wisselen, heb je hoogstwaarschijnlijk geen aparte context per taal nodig.