Drupal 6 theme add / edit content form - drupal

Drupal 6 theme add / edit content form
In Drupal 6, we can add new content type "content-type".
We want to theme /node/add/content-type by template file.
We want to theme the edit form /node/$nid/edit of this content-type also by template file.
How to do this?

For this you need to understand the naming convention of tpl files in Drupal. This link will help https://www.drupal.org/node/1089642
According to documentation,
"http://www.example.com/node/1/edit" would result in the following suggestions:
page-node-edit.tpl.php
page-node-1.tpl.php
page-node.tpl.php
page.tpl.php
Either you can try adding content-type in the naming as suggested(I have not tried it personally), or if there are few customization to be done, adding a check like
<?php if($node->type == 'content_type_name') ?>
over available variables in "page-node-edit.tpl.php" will also do.

Related

Changing the "standard template" name of the single.php post template

I have a Wordpress website, now i want to change the post template name how it displays in the Wordpress CMS. Now it's saying "Standard template", i want to rename this to "News", just for usability reasons.
I can't find a way to do this. I know you can create new post templates by creating new files, but it always takes the single.php as standard template. I'm also using a child-theme, so i dont want to delete the single.php file, just rename the text: "Standard template".
Thanks in advance.
I tried creating a new post template file with a custom title. This doesnt solve problem, as the single.php file will still be the standard one (i dont want the user to have to change the template).
You can use another single.php for another post type for example if you have news registered as a post type you could have a single-news.php and that file then would server all the single views of postype = news. But from what i understand you would like to create a template appearing to the user with a different name. For that the best practice is to create a directory inside your child theme and name it page-teplates. Inside this directory you can create as many different templates you want and wordpress will recognize them but adding the following code at the top of each template. For the sake of the example lets say i want to create a contact page template. I will create a contact.php file inside the directory page-templates and have these lines of code inside.
<?php
/**
* Template Name: Contact
**/
get_header();
/* My templates Code/Design Here */
get_footer();
The possibilities are endless.
The code in this post will generate a dropdown box similar to the one that you see in pages.
All it requires is a little editing of your child themes functions.php file .
In most cases, you just need to copy your single.php file to a new file name in your child theme and edit the functions.php file in your child theme. Name your templates as seen in the code Dimitrios posted.
consider using the premium elementor page builder to create custom post templates that you can apply at will.
Try a plugin like Post Custom Templates Lite

Drupal basic page doesn’t seem to use page.tpl.php

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

Theming node add form

I want to theme this page node/add/classified.
I tried creating page--node--add.tpl.php, page--classified--add.tpl.php, page--node--classified--add.tpl.php refreshing cache all the time...Nothing works
I tried also implementing hook_theme() and hook_preprocess_page().
If you want to create a tpl file for a particular content type as you mentioned in your post "node/add/classified", then I would suggest, you should go with the tpl name like this
Drupal 6 : page-node-add-[content type].tpl.php
Drupal 7 : page--node--add--[content type].tpl.php
in your case, this would be (assuming your Drupal version is 7.x):
page--node--add--classified.tpl.php
Hope it will help you.

Drupal 7 block.tpl.php does not exist

I am new in Drupal and try to create my own Drupal theme. I have copied the Garland theme from theme/garland and pasted it to sites/all/themes/(renamed mytheme). But when I search on how to integrate templates in Drupal, there I got that I need four mandatory files: comment.tpl.php, page.tpl.php, node.tpl.php and block.tpl.php but in that theme there is no file name called block.tpl.php, inspite I have a template.php.
Please guide me on this, do I need to create block.tpl.php by myself?? If I create it what would be its content and how do I use that, also what is the use of template.php in my site.
I am new in this CMS (Drupal) so any response would be appreciable and helpful for me.
You can create your own block.tpl.php by copying it form modules/block to your theme's folder (remember to clear the cache!). template.php should contain custom overrides to the theme functions, as well as implementations of process/preprocess hooks. You can find an in-depth discussion about how Drupal's theme system work by following this link and in general by searching drupal.org website.

new content type, with completely blank(body of node only) output theme files

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; ?>

Resources