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.
Related
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.
I'm new to Drupal CMS. Here I want to set front page link for main menu item. It set that for front page link as per Drupal guide. But, it gives an unexpected result example.com/.
Is there any way to display any front page or blank for my main menu item eg: example.com?
Note that I'm using a custom theme.
By default Drupal doesn't add slash if tag is used. You can try checking your rewrite rules.
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);
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.
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);
?>