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);
?>
Related
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.
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';
}
}
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.
How to generate 'a href="javascript:void(0)"' like link in CakePHP?
I make an application, the content will insert into the editor textarea when user click a list of image. I add a class to these images and write some code in the javascript file. Everything is going well.
But the link of the image is a URL address, but not 'href="javascript:void(0)' like URL. Anyone could tell me how to make it in CakePHP?
Thanks in advance!
<?php
echo $this->Html->link(
'/path/to/image/',
'javascript:void(0)'
);
?>
You can either set a path to the image or use the Html helper to generate the image tag code. The second parameter will set the href.
Don't believe there is any dynamic way, however when you are creating your form element you can set it in the options array 'href' => 'javascript:void(0)'