0

I find the pre-supplied list of selection rules to create panel variants to be quite lacking. For instance, if I am using panels to override taxonomy term pages, and I have some arbitrary boolean field on each term (say, "Is Blog?"), then I would like to create a panel variant based on this field being equal to TRUE.

However there is no such flexibility when using Selection Rules to create variants. Am I alone in thinking that this missing functionality greatly diminishes the power of Panels and panel variants?

How would a site builder, or developer, go about creating new "custom" selection rules?

0

Well, there is an inelegant workaround, suitable only for someone comfortable working with code. There is a choice in the Selection Rules dropdown called: "PHP code" where the contexts are available in the $contexts variable. This means all fields of the current taxonomy term are in there.

I ran this: return @$contexts['argument_term_1']->data->field_is_blog['und'][0]['value'];

It will return 1 if the is_blog field exists and has a value of 1. Otherwise (if the field does not exist or it otherwise evaluates to false), it fails silently.

I'm not totally happy with this solution, but it gets the job done.

  • Careful, Including php code in an open site could present a security problems allowing users undesirable access to your site. – Ashlar Dec 2 '11 at 14:54
0

We initially did it the way that you did. However, after a site security audit, we were told that we should not include PHP in that way (even though it's there and available). The solution is to create a custom rule using ctools access plugins. This page has an excellent breakdown of how to do it. We now have about 5 or so custom ones we use through custom modules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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