Dean Loh
Dean Loh

Reputation: 57

Drupal - Panels - use variants according to NID

I'm using Panels to overwrite node template (node/%node). I would like the system to use specific variant when a node is loaded. E.g. node 123 should use variant A and node 223 should use variant B. There isn't an option for me to determine that under Selection rules, I'm wondering if I should use PHP Code, and if I do, how should I go about writing the code?

I'm aware of the option of using Panels Node, but by using it, there is no easy way to edit the node thus rendering it a less than desirable choice.

Upvotes: 4

Views: 2147

Answers (2)

jenlampton
jenlampton

Reputation: 312

You'll need to do something like this...

  $nid = 11;
  if (arg(0) == 'node' && arg(1) == $nid && !arg(2)) {
    return true;
  }
  return false;

Be careful only testing arg(1) as in the previous answer, that will also match users (user/123) as well as any page view that accepts a numeric argument (articles/123).

Upvotes: 2

googletorp
googletorp

Reputation: 33285

In this case the easiest thing is probably to throw in some PHP code. It would be prettier to make an extension to the Panels selection rules, but this might be a bit overkill in this case.

Anyways something like

return arg(1) == 123;

should do it.

Your problem is probably Drupal/Panel cache. I just tested it, and it works fine.

Upvotes: 3

Related Questions