Add summary/teaser to Full content in drupal 7 - drupal-7

I want to have both Summary and Body in full content view in Drupal 7 but I can't understand how it is possible.

You can edit theme template files to do that. just edit node.tpl.php or page.tpl.php in your theme.
For example get summary in node.tpl.php:
// Load node summary view
$node_view = node_view($node,'summary');
// Get the summary
$summary = $node_view['body'][0]['#markup'];
Or use views to create the content you want.

Related

hide right sidebar on specific pages in drupal

I want to remove the sidebar from the specific page and all its subsequent pages in Drupal 7
My code is mention below.code is in mytheme_preprocess_node(&$variables) function
if ($variables['type'] === 'project'){
$node = $variables['node'];
if($node->type=='project'){
//print_r($node);
echo $node->type;
unset($page['sidebar_second']);
}
why don't you create a tpl file for that specific content type and remove the sidebar from there ? just an idea
Try restricting the block in Blocks UI or with the Context module.
You can restrict that sidebar content in admin panel itself. login as admin and configure that sidebar block to display only on perticular url.

Render drupal form in custom template

I'm trying to render DRUPAL content type form in a custom tpl that I created. But its just printing the hidden fields not the actual form.
I tried using drupal_get_form and drupal_render, but nothing works!
Can someone suggest me a link or reference to drupal theming guide?
Am I missing something?
You need to use drupal_get_form and drupal_render on 2 different steps.
$myForm = drupal_get_form('YOUR_FORM_ID');
print drupal_render($myForm);

Override custom content page markup Drupal 7

Although I've seen some 'clean' answers on this topic here, it still doesn't work in my case, which is the following: being in Drupal 7 with a completely customized theme, I have created a custom content with the machine name cco_product. I want to override the page markup for the page generated for this content type. I have tried, as per the documentation,
page--cco_product.tpl.php in the tmemes folder, based on /module/system/page.tpl.php, but my Hello world on top of this file doesn't show up.
Thanks for help
First, try clean your cache, if did't help, i can advise to look into the an array of templates for your page. Maybe one of your modules or your custom theme overrides array of templates like this:
function MYTHEME_preprocess_page(&$variables, $hook) {
//Add multiple suggestions for pages based on Node
if(arg(1) == 3) { //For node 3
$variables['theme_hook_suggestions'][] = 'page__contact';
} if(arg(1) == 4) { //For node 4
$variables['theme_hook_suggestions'][] = 'page__about';
}
}

insert node field into sidebar

I'm trying to figure out how to have sidebar content for a 'page' content type. I've created a fied in page called sidebar. Now how do I insert that content if it exists into the right sidebar? Would I use hook_page_alter().
CCK Blocks module will do it for you:
Don't be confused with "CCK" in name, Drupal 7 has fields in core so you don't have to install it.

Completely change the design of a page in Drupal 7

Is there a way I can fully customize a page in Drupal? I don't want the Drupal header or any other HTML generated by Drupal to show up, but I want to be able to access the Drupal functions.
Basically you want a new page template (as opposed to a node template). This does not quite work out of the box in Drupal 7 so there are a few steps:
Step 1
Create a new content type for this specially themed page, call it "special" or whatever...
Step 2
Add this code to your theem's template.php file. (Replace "yourthemename" in the code below with your theme's machine name, that is to say the name of your theme folder in /sites/all/)
function yourthemename_preprocess_page(&$vars) {
if (isset($vars['node']->type)) {
$vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;
}
}
Step 3
Create a new page template in your theme folder and name it after the new content type. so for example: page--special.tpl.php and "special" being the name of the content type. Customize away!
Step 4
Clear cache
Step 5
Create a new peice of content using your new content type -- it will be in the design of your new page template.
The end result will be like having a completely separate theme but staying within your existing theme.
Note, I wrote a blog post on how to do this for Drupal 6 but if you read down the comments, there are ideas and links how do this for D7 but basically what I have said here.
http://highrockmedia.com/blog/creating-custom-content-type-page-templates-drupal-php
You can run an alernative page.tpl.php file. Eg. page--front.tpl.php
Not sure it's the best way to do this but it will work. You can strip anything you don't want out of the file so it is totally different to other pages.
Drupal is pretty flexible:
<?php
$json = array(
'body' => 'This is the body of the page.',
'title' => 'This is the page title',
);
return drupal_json_output($json);
?>

Resources