The preprocess functions are really poor documented. I can't seem to wrap my head around understanding what is parsed through the standard $content var, and how to override that. I'd like to parse my $nodes (using node.tpl.php) in a different region than $content, in $content_right. Off course I can just place $content in my template files, but I want to respect the admin functions and keep them nicely formatted in a wider column.
Example:
---------------------------------------
| $header |
---------------------------------------
| admin div ($content) |
---------------------------------------
| $content_left || $content_right |
| || |
---------------------------------------
Note: this is only showing the relevant concept, I have 4 columns set up, adding one on the outer left and one on the outer right. These are filled with blocks. This works great.
This is what I'm trying to create:
The $content region is parsing Drupal messages and the admin stuff the usual way. However, when visiting the site normally; the height of the admin div is 0 or really small because of a simple Drupal message. Beneath it I'd like to have my $nodes parsed in $content_right, so I can use $content_left to fill in using blocks. When an admin logs in to edit content, he would use the full $content region for that, while Drupal omits the $content_right region (div) since you're not on the frontpage.
I'd rather not set up a block to have my most recent $nodes listed on the frontpage, since I believe using this region method is less expensive on high traffic (this is the frontpage where I want this to happen).
I have set up my theme and my regions correctly using the .info file, read the complete theming handbook, tried modifying the example function manually assign content to regions, tried understanding the preprocess_page functions, explored the drupal_set_content options, read how to convert your theme from 5 to 6, even pondered to force another version of node_page_default, but I can't seem to come nowhere near the solution.
This is what I think needs to be done:
a function in template.php like (pseudo-code):
theme_preprocess_page(&$variables) {
when $content has $node {
drupal_set_content($content_right, $node);
}
}
but I'm not sure about the following stuff:
- For this, do I need a preprocess_page, a preprocess_node or a preprocess_theme function?
- How do I recognize when Drupal is about to parse a $node?
- How do I keep the $node var a var, so that I can still parse it through node.tpl.php?
- Do I need to invoke this function in page.tpl.php? Do I need to flag it so it only invokes on the frontpage?
I've been wondering a couple of days in the IRC channels on this but nobody seems to be familiar with the $regions and / or preprocess functions in Drupal 6, after spending so much time on the forums and useless hacks in template.php I'm starting to get a bit desperate on this. I know it can be done (wouldn't be so hard in Drupal 5), and I'd like to have a clean solution to this; no core hacks, no module modifications, just nice and sweet some overrides in template.php without calling unnecessary and expensive MySQL queries in there. I know Drupal is powerfull enough to get this working, I just can't seem to see how.
Please help.
Comments
I'm not entirely clear on a
I'm not entirely clear on a few points.
Messages, help ect are not set through $content, but rather $messages, $help, $tabs etc etc - so simply moving $content to your region for front would do precisely what you want, e.g.
Now I take you know this already which is why I am not so clear.
You could do something like this...
...replacing the $content variable with a new region $content_centre
I am certainly no expert but I think there's a pretty major difference between manually assigning content to regions & re-assigning content from one to another.
EDIT: sorry, I pasted the wrong bit of code:)
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Correct!
You are quite right considering the message part, I was to eager to try to explain this in a clear way. However the complete admin part is parsed to the $content region as well, so I'd still like to seperate that. Your bit of code did the trick, thanks so much!
Eventually I totally omitted the $content region, since Drupal was parsing the $nodes twice after implementing the function. So in my .info I set up my regions like this:
And in template.php:
Again, thanks a lot :)!
Yea, totally removing the
Yea, totally removing the content variable is the only way my code will work, I'd bet my bottom dollar there is something we are both missing here (like I say, I am no expert), lets hope one of these gurus comes along and shines some light on this.
For the record I tried a few conditionals to make it work with the standard content variable but I couldn't quite wrap my head around it.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
well done!
well done finding something that works...
thanks for giving me the heads up :)