0

Hi I am desperetly trying to override the template of my D7 custom module's block here is my code :

  function lnr_block_info() {
    $menus = menu_get_menus();
    $blocks['actualites_filter_article'] = array(
      'info' => t('Actualités: Filtres Articles'),
    );


    return $blocks;
  }


  function lnr_block_view($delta = '') {
    $block = array();
    $menus = menu_get_menus();


    if($delta == 'actualites_filter_article'){
      $block['content'] = theme('actualite_filter_article');
    }


    return $block;
  }   

  function lnr_theme() {
    $module_path = drupal_get_path('module', 'lnr');

    return array(
      'actualite_filter_article' => array(
        'variables' => array('result' => NULL),
        'path' => $module_path. '/templates',
        'template' => 'actualite-filter-article',
        //leave off .tpl.php
      ),
    );
  }

The template of the module is loaded correctly, but once I copy paste it in the theme templates directory it is not overriden. (the name of the template file is : actualite-filter-article.tpl.php ). What aam i doing wrong ?

Thanks in advance

2
  • The cited code is in the .tpl.php file or in a custom module?
    – Wtower
    Commented Sep 10, 2014 at 14:19
  • In the custom module
    – Thony
    Commented Sep 10, 2014 at 14:20

2 Answers 2

0

I think you are missing the argument for the hook_theme so you can do it this way

/**
* Implements hook_theme().
*/
function lnr_theme($existing, $type, $theme, $path) {
 $items = array();
 $path = $path . '/templates';

 $items['actualite_filter_article'] = array(
  'path' => $path,
  'template' => 'actualite-filter-article',
 );

  return $items;
}

Give it a shot

0

All right I found where the problem came from, in this project I also used a custom theme named "lnr", the very same name as the one used by my custom module.

To solve it I renamed and reinstalled my module wich is the best course of action in my opinion (who knows what bugs this might induce ...).

If you don't want to rename your module you may also solve the problem by testing the type in your theme hook like so :

  function lnr_custom_theme($existing, $type, $theme, $path) {

    if($type == 'module')
    {
      return array(
        'actualite_filter_article' => array(
          'path' => $path. '/templates',
          'template' => 'actualite-filter-article'
        ),
      );
    }
    return array(); //will raise fatal error if void
  }

Credits goes to this guy : https://api.drupal.org/comment/19089#comment-19089

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.