I am pretty new to Drupal, but I am pretty familiar with PHP.
I am looking for the place in the code where the $content varible is contructed before being passed into the template. I see it passed around all over the place, but I can't seem to find where it is created.
I know that the $content variable passed in from the function phptemplate_page() to the template and that function takes the $content variable as an argument. So I looked up the calling function of phptemplate_page() and it was call_user_func_array(), and that is where I got stuck.
All I really want to do is figure out where the content for the front page is generated and make the HTML a little different.
How can I do this? I can't seem to find where the $content variable is being contructed.
Thanks.
Comments
Not exatly what you want.
If you want to theme the front page content, you can do it through the phptemplate engine without touching content.
Basically, if your frontpage is a single node you want to go to the node.tpl.php and manipulate the output conditionally.
another method is to just supply a different page.tpl.php for your front page, as outlined here http://drupal.org/node/46017
good luck
Sam Tresler
http://www.treslerdesigns.com
-------------------------------------
"A list of common problems and their solutions can be found in the Troubleshooting FAQ."
I should have said
I should clarify. there is no need to ever touch $content. As you can override *everything* at the theme level.
So figure out what your front page is, a page, a 'river of news' blog, or whatever, and then theme appropriately for the front page.
P.S. if your front page is a list, make it a view for easier themeing as well.
Sam Tresler
http://www.treslerdesigns.com
-------------------------------------
"A list of common problems and their solutions can be found in the Troubleshooting FAQ."
(No subject)
Create A New Theme tpl.php
I would add an argument to include page-front.tpl.php, or really whatever name you want, and theme the output there. Here is a nice little Lullabot article, its for 4.7 but should help to get you started regardless of your drupal version.
If you need more info than that just hit me up.
Peace,
-mpare
www.paretech.com
Thanks for the feedback
My front page may eventually be a node, or a node plus the default Drupal front page (the 10 most recent articles submitted), but right now it is just the default Drupal front page.
So all I really want to do is make a small, small change to the way the front page is currently displayed. Namely, I just want to add s between the teasers of the 10 articles that are displayed on the front page (or any other page for that matter).
Here is a link to the site: http://204.13.252.61/drupal_matt/node?page=253
I just want to make it so that the end of one teaser (with the "Login or register to post comments...Read more") is more distinctly separated from the next teaser.
I would like to learn more about the templating (and probably soon will) so that I am better able to customize the site, but this seems like it should be very easy.
What do you want to add?
You only wrote 's' which doesn't make a lot of sense.
Anyway, open the file node.tpl.php that should be in your theme.
Beneath the print $links part, add whatever markup you need.
Also you can do a lot with CSS at that part to, add space, borders, background images, etc.
good luck.
Sam Tresler
http://www.treslerdesigns.com
-------------------------------------
"A list of common problems and their solutions can be found in the Troubleshooting FAQ."
Sorry...didn't realize it would parse the HTML
The 's' that I wrote was originally an HR with the <>
Thanks, got it
Adding to the node.tpl.php file did the trick. I didn't realize that was the template that was being used to generate the teasers for the front page as well as the main node pages.
Thanks again.
Actually
Its not even generating the main node pages. The nodes on the main node pages are genrated by it, and the rest of those pages are still generated by page.tpl.php
ANyway, glad I could help. Cheers.
Sam Tresler
http://www.treslerdesigns.com
-------------------------------------
"A list of common problems and their solutions can be found in the Troubleshooting FAQ."
Every place on the internet
Every place on the internet that I have seen this question asked, it always gets the "Don't hack the core" lecture instead of getting answered. To better my own understanding of Drupal, is there anyone who does know Where the $content variable is created in Drupal? I have a custom node (an Openresort business) where there are several things that get lumped into the content, not all of which I want to be there. It would be a tremendous help in figuring out how to achieve the modifications I want if I knew where and how drupal creates the $content variable. Is this such dangerous knowledge that it must be kept a secret? I think I will try hacking the core just to see if my computer blows up or the Drupal police come to arrest me :-).
If someone can enlighten me regarding the $content variable, that would be great, but please no more "Don't hack the core" lectures. It is a free world (sort of) and Drupal is open source, so I will hack whatever I please.
In the same vein - I want to
In the same vein - I want to know how to use a hook_menu callback to return ONLY the contents of page.tpl.php's $content variable. I'm making an AJAX/AHAH - based site, and I can't figure this out. It seems like it should be theme_blocks - is this correct? It seems like you'd still have to let it know somehow what page you want the $content for... and in my case, this could either be a node or a view page.
Thanks!
node_load()
Assuming that you are using drupal 6 and that I understand your query;
$mynode = node_load(n);
$content = $mynode->content['body']['#value'];
no lecture - just comment
The $content variable sooner or later just ends up in a tpl.php file - surely preprocessing $vars['content'] to create $vars['myalteredcontent'] in the template.php file would be the neatest and most headache free option?
example template.php :
function mytheme_preprocess_page(&$vars, $hook) {
$vars['myalteredcontent'] = _alter_content($vars['content'])
}
function _alter_content($content){
// $altered = do something with $content['body']['#value'];
return $altered
// or return $vars['content']['field_mycckfield']['#value'];
}
PS - sorry if this comment is too late or does not address your concerns
Right...
... but nobody ever did answer the poor guy's question...
True
I am finding that the majority of posts are discussing what Drupal can do with no usefule information or answers. Unlike the 20 or so other CMS's I work with, 90% of my answers come from user sites and not from drupal.org.
This is recognized universally as an indicator of a poorly managed program (as a whole, not just the codeset). With the simple tasks I need answers for combined with just plain dumb implementation the MSDN is moving to second position in the useless/difficult category usurped by Drupal.
I am really trying to be nice here, but I am also rather disappointed. I am also getting discouraged to provide solutions via this avenue.
Am I missing something or is this really as bad as it reads? (compared to other CMS's and MVC's).
RTFM
Or of course, you could just RTFM!
http://drupal.org/theme-guide
The very first response addressed modifying the output in template.php.
For D6 the details are here: http://drupal.org/node/457740
For many modifications you can just edit the .tpl files.
Just because you don't know what's going on, doesn't mean that it doesn't make sense!
In node.module
I believe that $content is created in node.module (line 1010), using the drupal_render function.
Another Non-Answer
Here is what I did to accomplish what I think most people are trying to do when they want to alter the $content variable.
First I'll explain what I needed to do:
I was developing a site for an agency in drupal. I wanted to create the most intuitive way to edit page content as possible. It was pretty much a brochure site so I needed a way for the site admin to add/edit pages of the site. Rather than using a bunch of blocks and/or views and then requiring him to edit these individual pieces to effect change on the site I created a new content type called SubPage as this was going to be the format for nearly all interior pages. I used CCK and added all the fields that would be required to the SubPage content type.
Next, I copied the node.tpl.php file in my theme folder. I created a new file named node-sub_page.tpl.php and put it in the same directory. I pasted the code from node.tpl.php into this new file. I did this because drupal is apparently smart enough to see if there is a matching template file (node-.tpl.php) before loading the default.
Using this fresh template file I would be able to apply my css selectors around the field values. Or so I thought...
That's when I realized that drupal just outputs the $content variable. I needed to be able to add some <div>s around and within the output from content.
So what I did was:
Rather then try and hack into the core and create a custom function that would create the output the way I needed it I deleted the $content variable from my custom node-sub_page.tpl.php file and replaced it with this:
print_r($node);That told me all of the available information in the $node object. Using this I was able to create my own <div>s with my own selectors and then just output the exact field value I needed.
For example to put the image on the page I put:
<div id='sub_page_img'>
echo $node->field_image[0]['view'];</div>
This allows you to access each component of the $output to accomplish what you were probably after in the first place.
dissecting $content
Thank you, Danny.
This is by far the best answer to the question presented, which is how to display some of the constituent portions of $content when you do not want to present $content in its entirety in a new template.
Yes, it's a simple way of
Yes, it's a simple way of outputting ONLY the things you need, but after doing this, were you still able to edit the page?
$content is used by Drupal to provide for the page(s) used for editing. You better ensure that you can still do this... If you can or know of what I'm referring to here, by all means, explain what you did to maintain or retain the editing facility because I too removed $content from my page template in order to have ONLY specific pieces of data, but now, as luck would have it, I can no longer edit the page!
If someone is still looking
If someone is still looking for a way to do this, you can modify individual components of the $content variable using hook_nodeapi, with $op = 'view'.
Here's an example:
You can also access CCK fields and other components that end up on the $content variable. Try print_r($node->content) there to see all of them.