4

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.

Dean Loh
  • 47
  • 5

2 Answers2

3

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.

googletorp
  • 33,075
  • 15
  • 67
  • 82
  • @googletorp thanks for the quick response. That was actually the first thing I tried, and it didn't work, thus got me thinking if it wasn't the right method to begin with. – Dean Loh Mar 02 '10 at 00:40
  • 1
    return arg(1) == 123; This new code worked! Thanks heaps for the follow up answer! – Dean Loh Mar 02 '10 at 15:24
2

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).

jenlampton
  • 315
  • 2
  • 7