I want a means of triggering a different Context depending on the type of file used in a field on a given content type.

I have been struggling with trying to achieve this for a few days/weeks now after recently moving from D6 to D7. After trying it with Panels I've moved onto Context Module and Context Entity Field. I'm hoping I can finally get this sorted so all help appreciated thanks.

I don't know if it's my lack of D7 experience that's causing this. Basically, I'm working with one content type. It has a Multimedia asset field. I allow uploading, adding images and youtube media via url in this field. I was wanting to create a new page context if the field contains youtube video field. If it has an image then let's do another context etc. Only one of these filetypes are allowed per node.

Context Entity Field seems to only work if the Multimedia asset field has something, or not. I was wanting to use context on file type.

Is this possible or am I really missing some simple D7 point that wasn't there in D6?


Note that I am using Media Module for this Multimedia asset field.

  • sorry i changed the title as i had Video in there which wasnt correct.
    – Reg Gordon
    Mar 9, 2013 at 23:22
  • ok im getting smewhere i think. Does anyone know how i can find the "entity field value" from my errr content type? no errr field? it must be from my field. lets loook more...
    – Reg Gordon
    Mar 9, 2013 at 23:29
  • bah i give up. I dont think Conext or Conext Entity Field Can do this. It almost can. no i must be doing somethign wrong. lets keep at it
    – Reg Gordon
    Mar 9, 2013 at 23:48
  • here is a screen shot of my cOntext settings if it helps anyone to help me. Ive been at this forever it seems. Once i sort this i can actually get my site back in shap. thanks s7.postimage.org/47mpif27f/screen.jpg
    – Reg Gordon
    Mar 9, 2013 at 23:52
  • Anyone? Im still at it here. Failing miserably. Posted here there and everywhere. Dunno if its too easy or too hard to sort.
    – Reg Gordon
    Mar 10, 2013 at 5:43

1 Answer 1


Can I suggest a slightly different strategy? If you have the Rules modules installed - or are willing to install it - then can use a Rules condition to apply the specific test you want. If it passes that test, you can get Rules to set a field on your node that Context can respond to.

So, for example, you could have a Term reference on your content type that has three vocabulary items 'YouTube', 'Image', 'Empty'. Rules can set this field whenever the node is saved. And Context is able to respond differently depending on the Taxonomy Term that is present.

A downside is the user gets to see the Term reference field when entering data, but since it's changed to the right value on save anyway, this may not be a big deal. You can tell the user to ignore this on the form and hide it away, e.g. in a closed fieldset. Or if you are a Display Suite user, you can easily hide using configuration.

I've tested whether Rules can pick up the media type and can confirm it does so quite cheerfully. To start the process, add a new rule and choose React on event with the type 'Before saving content'. Supposing you have a field on your content type with the machine name field_media, then you will need to use a Data comparison condition that checked [node:field-media:file:mime] to see if it is equal to video/youtube or image\png etc. You may need to do a bit of fishing to get out all the relevant mime types. You'll then need to create an appropriate action when the condition is true. You'll probably want several rules bundled together in a Rule set.

A single condition will look a bit like this:

enter image description here

If you've not used Rules before, it can be a bit fiddly to set up the first couple of times, but well worth it. Knowing that it can detect the condition that is of interest to you, means that this is a solution that you can make work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.