I need to create a sidebar with various user information for the owner of each page.
For example, if I am viewing a poll, guestbook, blog entry or whatever owned by a specific person, the sidebar would contain information about that person with links to various relevant content.
This is turning out to be much harder than I expected and I wonder if I am missing something.
I am using the phptemplate engine. My first plan was to create a variable called "$page_owner" from $node->uid in _phptemplate_variables in templates.php.
However, I soon discovered that $node is often not available in this function. Apparently it is only provided if the URL is of the form /node/$uid, which it often is not. Eg blogs. Moreover, some objects like guestbooks have owners but are not created as nodes in the guestbook module. In other cases, comments on an object are not nodes, etc.
So my next plan was to create a global variable called $page_owner and define appropriately it in various modules.
However, it appears that no global variables I define in my modules are visible to template.php. The values are always blank no matter where I define them - eg. hook_menu defines a title field that the theme system can use, but no global variables set there can be accessed from template.php .
I have never seen this kind of behaviour in other PHP applications I have coded - it appears that Drupal is wiping out my global variables in the middle of the page creation process.
Does anyone have a solution? I am even thinking of appending my page_owner value to the page title, which at least gets passed through, and then removing it before displaying the page. But that would be ugly, ugly, ugly.
Does anyone have a better solution?
Comments
I think I recall that
I think I recall that instead of $node you should use $vars['node'] in template.php.
See here http://drupal.org/node/16383
Thanks, but I tried that -
Thanks, but I tried that - the issue I have is not the $node issue. It is documented in a few places that $node (and $vars['node']) is often not defined even for pages that have clear owners. I mentioned some of the reasons in my original post.
The problem that I have is that I set a $page_owner global variable in my modules and cannot access it in template.php.
I tried both techniques in hook_menu in my module:
global $page_owner;
$page_owner = $uid;
and
$GLOBALS['page_owner'] = $uid;
In both cases the value is blank when I try to access it in template.php.
My error
*Deep blush*
My error - the global variables work - I was just running the wrong version of my module!
Sorry for wasting your time.
I currently want to achieve
I currently want to achieve the exact same thing for my Drupal 6.13. Specifically on defining the owner of the guestbook. It's been over 2 years I know and that's still Drupal 4. Anything for Drupal 6? I've been searching around the forum but I can't find anything related to this matter.