-1

I have worked with drupal 8, i included twig template inside another twig template file like the bellow.

{% include module_path ~ 'templates/template.html.twig' with {
    'content': someVars,
 } 
%}

Now i need to do the same with Drupal 7.
Is there any way to do something similar in drupal 7 ?

2
  • Yep: include. Scope is inherited so the with doesn't have an equivalent
    – Clive
    Nov 14, 2018 at 10:42
  • Can you edit the question and be more specific about which template you want to include in which other and something that explains the scenario better?
    – AjitS
    Nov 14, 2018 at 10:57

3 Answers 3

2

I find the best way is to use hook_theme instead of dirty requires/includes. Can make for a really nice component driven workflow.

In module or theme:

    /**
     * Implements hook_theme().
     */
    function mymodule_theme($existing, $type, $theme, $path) {

      $path = drupal_get_path('theme', 'my_theme') . '/templates/components';

      return array(
        'my_template'  => array(
          'template' => 'my-template',
          'path' => $path,
          'variables' => array(
            'var1' => 'hello' 
          )
        ),
      );
    }

In your template

   print theme('my_template' array('var1' => 'yo'));
0

I'm not sure if this is a good practice, but you can do that in your tpl:

<?php 
$my_content = "test";
include "archive.tpl.php";
?>

Then, in your archive.tpl.php you can work with $my_content

0

Another option: within the outer template call "print render(theme($variables...))". It might also be possible call theme() in the preprocess function.

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.