Closed (fixed)
Project:
flatforum
Version:
4.7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
9 Feb 2007 at 15:43 UTC
Updated:
17 Sep 2008 at 03:11 UTC
Seeing as you're using phpTemplate, you get passed a whole load of variables when you load a page (or anything?).
Instead of having a separate _is_forum() function or doing a node load, simply do something like this:
function _phptemplate_variables($hook, $vars = array()) {
switch ($hook) {
case 'page':
if(arg(0) == 'forum' || $vars['type'] == 'forum' || $vars['node']->type == 'forum') {
$vars['template_file'] = 'page-forum';
}
break;
}
There are, as far as I can see, 3 situation (or at least there are on our site at the time of writing).
1) You're looking at the forum overview - check arg(0) as this page has no type per-se.
2) You're viewing a list of forums - this seems to have the forum type in $vars.
3) You're viewing a forum node - simply take a peek at the node object in the $vars array.
I hope this helps in some way!
PS: This wont work for comments...
Comments
Comment #1
nicholasthompsonCorrection - it will work for comments - this is an adaptation (work in progress) of the template that comes with the current 4.7 download...
I looked up the code for node_load and, once the overhead of loading a node is done once, its all stored in a static array. Therefore its not too bad loading a nid for a set of comments as they should all share the same node.
Comment #2
airblaster commentedSomehow I don't understand how to use this function.
Is there any case where node-forum.tpl is loaded outside a forum?
Comment #3
nicholasthompsonThat code either needs to be pasted into template.php or amalgamated with an existing variables function.
In theory - no... Also, in theory, node-form.tpl.php wont ever be loaded without the code above or the code in the readme for flatforum. Drupal wont know what it is.
Comment #4
azote commentedHi nicholasThompson, I tested your code with 5.1 and doing it like that it will use the node-forum.tpl.php even when the node is promoted been loaded from the front page.
So looks kind of weird having a forum like post embedded in the front of your website ...
Comment #5
airblaster commentedI guess you can fix this by using drupal_is_front_page().
Untested Code with added front_page checks :
Comment #6
azote commentedyeah nic that works ...
but I had to comment out:
>$vars['content'] = $vars['node']->body;on the node case because the content of the node on the front page was null..
any ideas why is this?
Comment #7
azote commentedops sorry for the previous post nic... I forgot to add the check for frontpage at the case for the node.
any ideas how to only remove the navigation for the forums only?
I tried this but it was just a 20secs guest...
Comment #8
michelleJust tidying up.
Michelle