Setting up the Variant – Contexts

You may or may not need to add your own 'contexts' to the panel. Some context is already built in – so for example if you have a 'node template', then the 'node' context is already there in the panel.

The context is basically data which is available throughout the panels. If you go to the 'contexts' tab and look down at the bottom, you will see a huge list of data available.

This summarises all the context data available. A context is given a keyword (like 'node') and you can reference it with %node. The data within it is referenced such: %node:title. This takes the title from the node.

You'll see quite a few places in panels which allow this kind of usage. You will see others (such as input to Views Arguments) where a drop down list of all the context data is available. Even more powerfully there are some places you can enter your own PHP code and access this context data.

In some cases you will find the standard context data isn't enough. For example we want to pass the all the taxonomy terms of the page to the view. The node has the standard %node:term-id for just the primary term. So we need to get the 'taxonomy term' context added into the panel.

Go to the 'Contexts' tab. Here you will see the following screen:

As a note: until you see a line with a specific context in it (not an 'Add context' button next to it), this context isn't actually there (unless it is a standard in built context). The lines with the buttons next to them are simply options to add a context.

There are 2 categories of context – plain vanilla and relationships.

Whichever you add, simply creates a new bit of contextual data to work with. The end result is the same – each is just a context.

We want to have the taxonomy terms related to our node, so we select (under the relationships heading), multiple terms from node (which are all the terms associated with the node)

We then click 'add relationship' which just adds this as a context. You get a configuration dialog.

Apart from selecting which vocabulary you want the term data from, you can leave everything else as suggested. The keyword is as defined above (such as %terms:XXX to get a value from this context). Click save.

These values are now available as references (using %terms:XXXX) or in our case to our view. When we go back to our 'content' tab and choose to 'Add content' and add a view (in this case our testimonials view which takes an argument of taxonomy term id), we get this dialog box:

You can see (unlike in the other dialogs) that this has a drop down selection of all the available context data which can be passed into the view. As long as you have the 'CTools Views' module enabled, when you create an 'Argument' in your view, then this dialog box will ask you what to pass into that argument. Here we choose for the 'Term ID of all terms' to be passed in. Therefore when someone goes to a page about 'Studio Photography' which is categorised as such in our taxonomy, then only testimonial which are also categorised that way get shown in this panel.

That's pretty much it – your content is now very dynamic.