I'd like to do something like the following:
If a user goes to node/15
, my node.tpl.php
file is used, as normal, to generate HTML.
If a user goes to node/15/animal/7
, then my node.tpl.php
is still used, as expected, but it has a variable in scope called $animal
, set to the value that I would get from loading an animal.
So, the URL schema would look something like the following: node/%node/animal/%animal
. I want this behavior so that if the user goes to node/15, that's fine, but if they attempt to go to node/15/animal/100 and animal 100 does not exist, the user gets a 404.
The problem I'm running into is that this requires functionality from several distinct areas of Drupal, and I don't know how to make them work together. Adding a custom URL schema would be done in hook_menu()
, which requires a page callback. Using anything other than node_page_view
would cause the node not to be rendered as normal. BUT, adding a variable to the template's scope would require implementing moduleName_preprocess_hook()
, which I only want to conditionally fire when the user hits this specific URL schema.
I could of course manually check the contents of the requested URL myself, perhaps during moduleName_preprocess_hook
, but this seems a little too low-level. Surely Drupal has some sort of way to accomodate what I'm trying to do?