Drupal 6: print all body field content to node template file - drupal

I tried to display body content with:
<?php print $node->content['body']['#value']; ?>
However, it doesn't display all body content, it just display first paragraph of body content, sometimes 2 paragraph if it is short :/
I need to print all body. how can I do that?
Thanks a lot! Appreciate helps!

The shortened body content hints on it being filled/rendered for 'teaser' view instead of 'full'. In what context do you issue this print statement?
EDIT: The node templates are usually used for both, teaser and full output, but the decision on what to use, as well as the population of the content entries in the node object happen outside of the node template files. Within the node template file, the variable $teaser will be TRUE, if the node is to be shown as a teaser.
So you need to check in what context your node template gets called, as you'll have to configure that context to render the node as 'full'. This could be in many places, depending on who is responsible to provide the nodes you want to theme, e.g. if the node template gets called from a view, you'll need to configure the view to use 'full page' output, if it comes from a module, you'll need to check with the module settings, etc...

In node.tpl.php try
<?php print $content ?>
However,
<?php print $node->content['body']['#value']; ?>
works for me as well.

To get control over your teaser length the master value is set with Post Settings.
(Length of trimmed posts)
To control this by node type try: http://drupal.org/project/teaserbytype
NOTE: Teasers are cached so you'll need to http://drupal.org/project/retease
However, if you want to just get it done in the node template you could run a node_load() and have everything... but that's not the best practice.
FYI: you can control what CCK fields show up in $content under Display Options.
PS: In teaser mode I often make use of truncate_utf8().

Related

Placing block inside a node (positioning block between specific elements in node's content)

Basically I created a webform and enabled it as a block, now I want to put that block inside a specific node. I can do that by placing it in a 'content' region and defining the specific node BUT it displays at the end of the content. Now how can I move it between specific elements inside the content?
The node is using a page-type....tpl.php which is used by 5 other nodes as well so I cannot change the code.
To visualize it looks like:
[ content ]
-description text-
-list of videos-
[ end of content ]
and I need to put my webform between the text and the video list. Is there a way?
There are many roads you could take, but since you said you're considering the template file: Why not use a node-specific template, since page is a node type?
Say you're on node/123, then you could use a template named node--123.tpl.php
(see Drupal 7 Template (Theme Hook) Suggestions) and embed your block right there.
Alternatively, you could provide a reusable token in a custom module via hook_token_info and combine it with the commonly used token_filter module. But that might be over the top, if it's just one node you need to touch.
For Drupal 7 a bit of a hacky way to display the contents of a block in content would be to enable the PHP Filter module. Then edit your node and switch to the PHP code Text format and add this code
<?php
$block = module_invoke('block', 'block_view', '1');
print render($block['content']);
?>
where '1' is the block id found in the URL when you edit the block and be sure to include the PHP tags.
Also see this page https://www.drupal.org/node/26502 for more information on placing blocks.
You can use the EVA module to add the webforms in the node as a field.
You basically create a view and choose the "eva field" option then you make sure that this view selects only the webforms you want to have and relates it to the node (the EVA module documentation has much better examples than I can provide).
After you have added it as a field you can place it anywhere in the node.
There is also the Block reference module that could help you.

How to hide title from page node Drupal

I'm trying to remove the title of a page node on Drupal. I have this page:
And I want it to look like this:
As you can see, I want the title to be removed, but only for taxonomy terms. If I try to erase it using CSS, I erase al page-titles, so I wanted to use this module, that allows administrators to auto-generate node titles and hide it.
I go to structure -> type content -> my type content, and edit it. I activate the module, and I want to auto-generate titles depending on the node category. I think it should look like this, but it doesn't work...
Any ideas why?
EDIT: Sorry, I forgot to say: yes, when I activate the module, use it, and select the category as the auto-generated title, it works. But it doesn't hide the title...
It also launches this mistake:
Use Exclude Node Title module.
https://drupal.org/project/exclude_node_title
Setting for this module:
Click on Module->Exclude node title->configure
Home » Administration » Configuration » Content authoring
Select All nodes from Basic Page
Check Full Content for hide title from all cms page except home page
Check Teaser for hide title from home page.
If you want to remove the title, you should look into overriding the page and node templates.
page.tpl.php and node.tpl.php
All you need to do is click "View Source" on both of those and copy them to your theme folder. From there you can modify both as required.
From what I can gather, you'll want to remove the print $title from your node.tpl.php.
Have the similar issue before, as far as I remember, I just added some if statement to the code:
<?php if (blah-blah-blah): ?>
<h2> <?php echo $title; ?> </h2>
<?php endif; ?>
Hope, it'll give you a clue.
Some other thoughts: you can make an if statement or rewrite it not only in page.tpl.php but create some specific page-node-type.tpl.php file and overwrite only its $title, or you can try to customize page's output via Views/Panels modules as well.
Also, could you please make more clear, what title do you want to remove? Page title or node title? And it should be removed only when you are looking nodes associated with some taxonomy term (in other words, when you are on /taxonomy/term/n page), am I right?
By using the Context module, you can add classes to the body so you can target just the taxonomy pages in CSS.
Using Context module to set body classes
Sorry guys, it was as easy as hide title tag on "manage presentation"...
You are all right on your responses, but they were not exactly what I needed... thanks!
Use Exclude Node Title module.
https://drupal.org/project/exclude_node_title
another nice solution for specific nodes, is to use the standard $title_prefix/suffix vars, which should be implemented by every theme. using the standard class element-invisible in page preprocess ..
like:
/**
* Implements hook_preprocess_page().
*/
function YOUR_THEME_preprocess_page(&$variables) {
if (isset($variables['node']) && $variables['node']->nid == 1) {
$variables['title_prefix'] = array('#markup' => '<div class="element-invisible">');
$variables['title_suffix'] = array('#markup' => '</div>');
}
}
Every page should contain a heading.
You should always maintain a structured hierarchy of headings within any web page. You should never have a blank heading or even hide it with display:none;. Hiding any content which isn’t viewable by your visitors but is by search engines is against Google’s guidelines as your intention is to only manipulate search engine results by including it. Restyle a H1 so it fits into your design is the best option.
If you still have to hide it then a better option would be to either create a template for that node, content type or page and simply not print the heading.
Or if you want to use CSS then use position:absolute so the heading doesn’t use any space where it is located in the page and text-indent:-9999px; so the text is moved off the screen and no longer visible but at least can be read by screen readers and search engines.
This is how I did it, Switch statement
// Get the name of node
$node_name = node_type_get_name($node);
// Then just add the content types you wish to exclude by overwriting the // $title object with an empty string
switch ($node_name) {
case 'Home page':
$title = '' ;
break;
case 'Event':
$title = '';
break;
case 'Offer':
$title = '';
break;
}

Displaying a Drupal content type field outside of a node

I have created a custom field on a content type in Drupal 7 which I need to display outside of the node, in a separate area on the page.
Similar to how the $title variable works (in which you can place this where you like in the page.tpl.php file) I would like to be able to create another variable called $subtitle which would call the data from the current node and allow me to print out the variable in an area on the page.tpl.php file.
I've seen a view examples seeming to use views and blocks to accomplish this task, but that seems a bit excessive and wondered if there was an easier way.
There is an easier way, you do need to bear in mind though that not every page is a node page, and not every node page will be of the right content type so you should be selective. Just add this to your theme's template.php file:
function mytheme_preprocess_node(&$vars) {
$node = $vars['node'];
if ($node->type == 'my_type') {
$vars['subtitle'] = $node->field_my_field[LANGUAGE_NONE][0]['value'];
}
}
Then in page.tpl.php you should do something like this:
if (isset($subtitle)) :
echo $subtitle;
endif;
Make sure you clear your caches (at admin/config/development/performance) once you've implemented the hook in template.php or Drupal won't pick it up.

Custom theming for content type in Drupal

I can apply a custom theme to a certain content type in Drupal by copying the node.tpl.php file and placing the name of my content type right after the "node" in the file name and appending an hyphen. Ok, the new name is: node-page_two_columns_images.tpl.php.
But that won't give me much flexibility if I am not able to edit the way each of the fields of my content type are rendered. If you get the node.tpl.php file, here is the line I am interested in:
<?php print $content ?>
I need to edit the way the elements in $content are rendered. Why? Basically because the title of the page needs to go between two of these elements... more or less like this:
<div id="field-1-of-my-content-type">[stuff1]</div>
<h1><?php print $title ?></h1>
<div id="field-2-of-my-content-type">[stuff2]</div>
Is there a template file I can create to replace the elements in this $content variable or do I need to write my own specific function?
Thank you!
check out the content template module.
Instead of using $content, you can print out all the elements yourself, as they are available in the node template. That way you can arrange the title and CCK they way you want to.
Update:
The easiest way to theme a node with CCK fields is to use $field_[field_name]_rendered, it has the themed version of the CCK field. CCK creates that variable to make theming the node easier.

How do you remove the default title and body fields in a CCK generated Drupal content-type?

When you create a new content type in Drupal using the Content Creation Kit, you automatically get Title and Body fields in the generated form. Is there a way to remove them?
If you're not a developer (or you want to shortcut the development process), another possible solution is to utilize the auto_nodetitle module. Auto nodetitle will let you create rules for generating the title of the node. These can be programmatic rules, tokens that are replaced, or simply static text. Worth a look if nothing else.
To remove the body edit the type, expand "Submission form settings" and put in blank for body field label. For title you can rename it to another text field. If you really have no need for any text fields you can create a custom module, say called foo, and create function foo_form_alter() which replaces $form['title'] with a #value when $form['type']['#value'] is your node type.
No need to install anything:
when editing the content type, press "Edit"
(on the menu of Edit | Manage fields | Display fields )
click on the Submission form settings
on the Body field label:
Leave it blank, it would remove the Body field.
If you're not a developer (or you want
to shortcut the development process),
another possible solution is to
utilize the auto_nodetitle module.
Auto nodetitle will let you create
rules for generating the title of the
node. These can be programmatic rules,
tokens that are replaced, or simply
static text. Worth a look if nothing
else.
And to add on to William OConnor's solution...
The module is poorly documented unfortunately. It's really only effective if you use PHP with it in my opinion. Check off the "Evaluate PHP in Pattern" and type into the "Pattern for the title" field something like:
<?php echo $node->field_staff_email[0]['email']; ?>
or:
<?php echo $node->field_staff_name[0]['value'] . '-' . gmdate('YmdHis'); ?>
...where I had a field with an internal name of "field_staff_email" and was using the CCK Email module -- thus the 'email' type was used. Or, I had a field with an internal name of "field_staff_name" and was just an ordinary text field -- thus the 'value' type was used. The gmdate() call on the end is to ensure uniqueness because you may have two or more staff members named the same thing.
The way I discovered all this was by first experimenting with:
<?php print_r($node); ?>
...which of course gave crazy results, but at least I was able to parse the output and figure out how to use the $node object properly here.
Just note if you use either of these PHP routines, then you end up with the Content list in Drupal Admin showing entries exactly as you coded the PHP. This is why I didn't just use gmdate() alone because then it might be hard to find my record for editing.
Note also you might be able to use Base-36 conversion on gmdate() in order to reduce the size of the output because gmdate('YmdHis') is fairly long.
The initial answers are all good. Just as another idea for the title part... how about creating a custom template file for the cck node type. You would copy node.tpl.php to node-TYPE.tpl.php, and then edit the new file and remove where the title is rendered. (Dont forget to clear your cache).
Doing it this way means that every node still has a title, so for content management you aren't left with blank titles or anything like that.
HTH!

Resources