0

I would like to pass variables to a single specific template file(tpl.php). My setting is the following:

my_entities.module

function my_entities_theme($existing, $type, $theme, $path) {
  return array(
    'my_entities_property' => array(
      'variables' => array('element' => null),
      'template' => 'my-entities-property'
    )
  );
}

I am using a template file at my_theme/templates/my-entities-property.tpl.php

In the module file I am trying to invoke a preprocess function to add a variable but it is not being invoked.

function template_preprocess_my_entities_property(&$variables) {
  $variables['test'] = "test";
}

How could I make this work? I followed https://www.drupal.org/node/2275895#comment-8832701 but it seems that I am doing something wrong.

1

You should put your template in your module as well.

my_theme/templates/my-entities-property.tpl.php

Make sure to update your theme function like this :

function my_entities_theme($existing, $type, $theme, $path) {
  return array(
    'my_entities_property' => array(
      'variables' => array('element' => null),
      'template' => 'my-entities-property',
      'path' => drupal_get_path('module', 'my_entities') . '/templates'
    )
  );
}

Try to use THEME_preprocess_my_entities_property(&$variables) in template.php instead.

  • Using both dpm and watchdog to register activity nothing happens. – Potney Switters Jan 21 '15 at 11:45
  • Where do you use your dpm ? – pbonnefoi Jan 21 '15 at 11:55
  • In the function to check that it goes in. – Potney Switters Jan 21 '15 at 11:58
  • In your module do you also have your template in my_entities_theme/my-entities-property.tpl.php ? – pbonnefoi Jan 21 '15 at 13:58
  • 1
    I think in order to declare a Drupal template you should always put it in your module and then if you want to override put it again in your theme folder. Try to put it in my_entities_theme/templates/my-entities-property.tpl.php – pbonnefoi Jan 21 '15 at 17:06
1

In module preprocess function is moduleName_preprocess_[theme_function_hook]. here it will be my_entities_preprocess_my_entities_property

  • Using both dpm and watchdog to register activity nothing happens. – Potney Switters Jan 21 '15 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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