3

I override template in my custom theme na (templates/block--[module]--[delta].tpl.php) and I would like to include other template (from the same directory) into this. Can I do it and how?

Directory structure

sites\all\themes\
   my_name_of_theme\
        templates\
             block--views--front-page-block-1.tpl.php
             example-file-template.tpl.php

block--views--front-page-block-1.tpl.php (concept what I want to do):

<?php 
     /* init $path (or maybe it is not needed) */
     include($path . 'example-file-template.tpl.php');
?>
9
  • include it, maybe? What have you tried? What is your problem, exactly?
    – Mołot
    Sep 9, 2014 at 11:10
  • Please, take a look on my edit @Mołot
    – kspacja
    Sep 9, 2014 at 11:19
  • "or maybe it is not needed" - have you tried, with and without? If so, why "maybe"? If not - why not? it would take you a few minutes to try. Far less than asking a question here.
    – Mołot
    Sep 9, 2014 at 11:22
  • It was only contept - I don't even know how to it. Normal include doesn't work. There is variable $path to highlight that maybe I need to create/generate path but I don't know how
    – kspacja
    Sep 9, 2014 at 11:31
  • 3
    @kspacja drupal_get_path('theme', 'my_name_of_theme ') gets you what you need
    – Clive
    Sep 9, 2014 at 11:36

2 Answers 2

12

You can get another drupal theme path with drupal_get_path('theme', 'theme_name'); and finally

<?php 
     include(drupal_get_path('theme', 'theme_name').'/example-file-template.tpl.php');
?>
2
  • also path_to_theme() works for the current theme, and is shorter. Sep 15, 2014 at 8:46
  • @AlfredArmstrong yes, but he need to use the theme files in current theme .so need use path of not default theme .
    – Yuseferi
    Sep 15, 2014 at 9:44
0

You can use path to theme (Uses the current allowed theme):

<?php
include(path_to_theme().'/templates/TEMPLATE_NAME.tpl.php');
?>

Or Drupal get the path (You can set the theme you want to use):

<?php
    include(drupal_get_path('theme', 'THEME_NAME').'/templates/TEMPLATE_NAME.tpl.php');
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.