Title says it really. Basic pages created in Drupal don’t seem to use the page.tpl.php file as a template.
If I edit the html.tpl.php file, those changes apply to every page, and it causes errors when I load a basic page.
I have also tried to copy the page.tpl.php file and name it page—basic-page.tpl.php to no avail.
Any idea what’s going on?
Also, how do I go about changing the page_top variable to include more content?
Lastly, the default page.tpl.php file has $page variables and things like $page_top and the like.
How would I call the title from the page only and the body text of a page only?
I’m using Drupal 7 and a custom sub theme.
The aforementioned files are in the template folder of the theme and I did clear caches when I added them.
Add $conf['theme_debug'] = TRUE; in settings.php and clear cache, reload page and check view source.
It will display the template file suggestions.
page.tpl.php file common for all pages. Just print anything to the tpl and run any node of basic page as well as other content type page and check if its working or not. If page.tpl.php not working for basic page only, then check your template.php file.
For print a page title just need to use following code:
<?php print $title; ?>
For print body text you need to use following:
<?php print render($page['content']); ?>
This may depend on the theme you are using. But I guess you are actually meaning page--page.tpl.php (double dashes). Which will be taken into account after you added the following snippet to your theme's template.php. Replace MYTHEME with your theme's machine name.
function MYTHEME_preprocess_page(&$variables) {
if (isset($variables['node']->type)) {
// If the content type's machine name is "my_machine_name" the file
// name will be "page--my-machine-name.tpl.php".
$variables['theme_hook_suggestions'][] = 'page__' . $variables['node']->type; // (double underscores)
}
}
See Template (theme hook) suggestions, where I also got above snippet from.
active theme debug for inspecting the template source and you get a different suggestions to user it (just avoid using node/nid).
commend drush to enable theme debug drush vset theme_debug 1
Related
I'm new to drupal, so sorry in advance or any mistake, feel free to correct.
I don't really know what exactly that I have done cause the problem, but content's fields (for all content types)
is not being shown (the pages are empty beside the title).
When I edit the information it appears.
In the past the information appeared.
It happens only for a specific theme (business_theme), for other themes (drupal's default) the info' appears.
any idea or help will be great
You need to assign Main page content block to a region that already exists in your theme.
First; Declare the region in your theme's .info file.
regions[content] = Main Content
Second; Print the region inside your page.tpl.php file.
print render($page['content']);
Last; Assign the Main page content to the region from the Blocks manager page. ?q=admin/structure/block
After further investigation, It seems that when our own theme is being the default, no node.tpl.php is being called (does that makes sense?).
I add the code
<?php
print '<pre>';
var_dump(get_defined_vars());
print '</pre>';
?>
to each node*.tpl.php file and cleared all caches.
when our theme is working no changes appeared,
when enabling batrick theme the added code was working.
This happens only in the page itself, i.e. when entering to localhost/drupal/node...
in the front page the added code worked for both themes.
any ideas?
tnx
I am working on a drupal 7 site and am very new to this. I need to create a totally separate home page from the rest of the site. I notice the head is built in the html.tpl.php file where all the scripts are loaded. I would rather not load scripts to the rest of the site that will only be used on the front page. Also I have found that drupal adds some code to the end of my script rendering it useless.
/js/image_scale.js?lwhgie"
What is going on here and how do get better control of this?
Thanks
Just to add a couple of points:
If you want to aggregate your homepage JS (which you may or may not) then you shouldn't add the stylesheets manually to the template file. You can add them in hook_preprocess_page(), something like this:
/**
* Implements hook_preprocess_page().
*/
function MYMODULE_preprocess_page(&$vars) {
if ($vars['is_front']) {
$path = drupal_get_path('module', 'MYMODULE');
drupal_add_js($path . '/MYMODULE1.js');
drupal_add_js($path . '/MYMODULE2.js');
$vars['scripts'] = drupal_get_js();
}
}
Also I have found that drupal adds some code to the end of my script rendering it useless.
/js/image_scale.js?lwhgie"
That shouldn't render your script useless. From the comments in drupal_get_js():
A dummy query-string is added to filenames, to gain control over
browser-caching. The string changes on every update or full cache
flush, forcing browsers to load a new copy of the files, as the
URL changed. Files that should not be cached (see drupal_add_js())
get time() as query-string instead, to enforce reload on every
page request.
you could create a new template called page--front.tpl.php in your theme folder and this will be your template for the homepage. Now you can add/remove any html markup you want. for more info take a look here: http://drupal.org/node/1089656 . Also, you could "tell" drupal to use your custom template file using hook_preprocess_page() in template.php file in your theme folder. See the comments on the link I posted earlier
I am using WordPress 3.2.1 ,
Page template selection drop down is missing on Pages (Add,Edit)
wp-admin > Pages >Add New > Page Attributes
I Edit the Template Page Default page as below code
/*
Template Name: New Template
*/
But still the template drop down no visible , my older version of WordPress it display by default.
Following is the screen shot for more idea
I solved this problem solved by adding the typical following code:
/*
Template Name: Custom
*/
Don't add any spaces after Name:
It'll work if you use template name: as well.
It might help someone: check if your index.php file is in place.
If it's not there, wordpress treats the template as corrupt and it doesn't display the template selection.
This should be simple to troubleshoot. The requirements for the page template to work are straight forward:
The template needs the page title in the top of the file like you've shown (the title needs to be wrapped in a PHP tag, you probably just didn't add it with your example bu I want to make sure you havne't overlooked it):
<?php
/*
Template Name: Custom
*/
?>
The second requirement is that the file is in the root of the theme folder.
With those two requirements in place, it should work. If it isn't working you nave a few possible issues. I list a few off the top of my head:
You might need to re-install WordPress in-case a file was corrupted
during your last update.
It's possible someone has altered the WP-Admin layout using users
roles.
That's all I can thing of at the moment, let me know how it turns out.
I had the same issue. It actually turned out to be a missing style.css file within the template directory in my case.
This happens because the get_post_templates() in class-wp-theme.php first checks for errors. If it finds any then it returns an empty array (no templates are displayed).
A side effect of this is that saving a page would clear the existing template and use the page.php instead.
So in short if the errors() method of your theme returns any errors then no templates dropdown.
hope that helps someone.
Same issued, I found out that in appearance panel in your WordPress dashboard the stylesheet is missing. You shouldn't rename the style.css in your theme folder.
Not sure if this will help anyone, but we solved the problem by disabling our theme and re-enabling it again. We had some other theme folders in the theme directory that we weren't using so we deleted those out as well. good luck, it's a really random problem to solve!
yeah!template dropdown not showing because you have no template So how to solve this::---
1 create template folder in theme
2 create a template in this folder
like:-
<?php /* Template Name: Home */ echo "template"; ?>
and check-in page dropdown will be there.
I've just discovered that if you want to alter a specific page (or group of pages) all you need is to add templates file to the core templates. For instance, I need to theme my /helloword page using a page--helloworld.tpl.php and node--helloworld.tpl.php template files.
Now all I get is a blank screen so I tried to write a preprocess function that adds support for custom theme files like:
<?php
/**
* Adding or modifying variables before page render.
*/
function phptemplate_preprocess_page(&$vars) {
// Page change based on node->type
// Add a new page-TYPE template to the list of templates used
if (isset($vars['node'])) {
// Add template naming suggestion. It should alway use doublehyphens in Drupal7.
$vars['template_files'][] = 'page--'. str_replace('_', '-', $vars['node']->type);
}
}
?>
I see no syntax error but I still get a blank screen. Still no luck
Is someone able to figure out what's wrong in the code/routine?
Drupal7 + Omega Sub-Theme
Kind Regards
I think there's a tiny bit of confusion here: a template file named node--type.tpl.php will automatically be called for any node which has the type type...you don't need to add the template suggestions in yourself.
There is one caveat to this, you have to copy the original node.tpl.php to your theme folder and clear your caches otherwise Drupal won't pick it up.
Also you don't want to use the phptemplate_ prefix...rather you want your function to be called MYTHEMENAME_preprocess_page.
Your code to add the page template based on the node type looks spot on, see if you still have the problem after you change your function name and clear the caches.
Hope that helps :)
I have a content type that is only used for scripts on my drupal site that should return json data. So the issue then becomes that I can't have any of the theming elements of the site in the output.
So I know I need blank (only the output variable) tpl files for the following:
html.tpl.php
page.tpl.php
region.tpl.php
block.tpl.php
field.tpl.php (the manual says this isn't used but its the only way I could find to remove field divs around the body of my page)
So my question is, how can I create all of the content specific files for this content type? I know its easy to do a theme override in template.php BUT I can only get it to work for html.tpl,page.tpl and thats it. Drupal seems to ignore any content specific functions from region down to field.
I noticed you tagged this drupal-7, which I haven't tried yet. But, in Drupal 6 I would accomplish this by adding a new page template to $vars['template_files'][] in the page preprocess function of template.php. Example:
$node_type = $vars['node']->type;
if ($node_type == '{your content type name here}') {
$vars['template_files'][] = "page-" . $node_type;
}
If your content type was called 'scripts', then Drupal will look for a page called page-scripts.tpl.php, which will contain only one line:
<?php print $content; ?>