0

I am working on a module for Drupal 7. I have a template defined for my content type as node--[content type].tpl.php and placed it in the "themes/[selected theme]/template" directory. I want to keep this template in my "module" directory instead. So when the module is installed I don't have to place the file in to the selected theme folder every time. Is there a way to do this?

Thank you all in advance.

I have less than 10 rep so I cant answer my own question so I'll just modify the question

The following is working for me some how. For both case node edit form view and node view

function [content type]_theme() {
   return array(
    '[content type]_node_form' => array(
          'arguments' => array(
              'form' => NULL,
            ),
        'template' => 'node--[content type]--edit',
        'render element' => 'form',
        ),
    'node__[content type]' => array (
          'variables' => array(),
          'template' => 'node--[content type]' ,
          'base hook' => 'node',
          'path' => "sites/all/modules/[content type]_update/[content type]_update/[content type]/",
        ),
    );
}

I don't completely understand this but it's working.

user3106759
  • 438
  • 3
  • 15

2 Answers2

0

This link should get you going: http://www.wdtutorials.com/2011/06/13/drupal-7-how-create-custom-theme#.U6sZ741dXag

You basically want to create a new custom theme. In addition to the above tutorial, create a new folder 'templates' and add your .tpl files in there instead of the core themes folder.

Emir Memic
  • 270
  • 1
  • 3
  • 14
  • Actually some one before me worked on the module. He has created a template node--[content type]--edit.tpl.php which is attached to the edit form of the [content type]. I found a this code `function [content type]_theme() { return array( '[content type]_node_form' => array( 'arguments' => array( 'form' => NULL, ), 'template' => 'node--[content type]--edit', 'render element' => 'form', ), ); }` I dont Know how to do similar thing for my node [content type] view – user3106759 Jun 25 '14 at 19:11
  • you need to add the path element to the array. This might help: http://stackoverflow.com/a/7927679/3147901 – Emir Memic Jun 25 '14 at 19:20
0

You can use the below format to specify the template path. Then you can place the tpl file in your module folder.

function MODULENAME_theme() {
    return array(
        'yourcustom_theme' => array(
            'template' => 'mypage', // template file called mypage.tpl.php
            'path' => drupal_get_path('module', 'MODULENAME'),
        )          
    );
}
JSunny
  • 477
  • 2
  • 7