I Heart Technology Blog

by Nyberg Technology


How To Create An Edit Tpl For A Node Type In Drupal 7

by Darryn Nyberg

Resources > Nov 20, 2018


SCENARIO

I need to theme the edit page for ONLY article node type

GIVEN you have a node type of "article"

AND you want the node type to have its own edit template

WHEN you add/edit a node type of "article"

THEN the custom node type (edit "edit article") template is used.

The following works in Drupal 7

The steps

  1. Create a template file (the name is completely up to you).
  2. Drop some code in your themes template.php file
  3. Clear site cache.
  4. Code for your new "edit" template

1 - Create template file

Name the file whatever you want. For the sake being simplistic, we will name it "article--edit.tpl.php"

Place that article--edit.tpl.php file in your theme directory where your other tpl files are.

WHY DO THIS?

There is no template suggestion for a specific node edit form. You can do a global edit form page such as is in the documentation on Drupal "page--edit.tpl.php but this is not specific to one node type. So, you need to create a tpl file with the name you desire to be used for the "article edit" page. We edit the template.php file so that your site knows to use this new tpl file you created when editing any article node type.

2 - The template.php file

The following code is to be used in your template.php file. If you don't have one then create it.


 array(
      'arguments' => array(
          'form' => NULL,
      ),
      'template' => 'templates/article--edit', // this must be the name of the file you created. Our file was title "article--edit.tpl.php" so we use article--edit
      'render element' => 'form',
    ),
  );
}
?>

3 - Clear your site cache

If you miss this step then this will will not work.

4 - Code for your new "edit" template

Use the following so that your edit page has content. The "themeing" is up to you.


About

The I Heart Technology Blog is written by our team members at Nyberg Technology and NyTechEd.

We hope to educate and support the community through providing resources and premium software development.

Become A Team Member

Are you a developer? Are you a tech blogger? We would love to hear from you!

(559) 335-3556

info@nybergtechnology.com
Nyberg Technology
516 Villa, #13
Clovis, CA. 93612