1

I am trying to override views-view-field.tpl.php in my custom module as suggested in override views-view-fields.tpl.php in custom module but looks like it's syntaxes are old.

My codes are like:

In mymodule.info

 ; $Id$

  name = My Module
  description = Create custom views template.
  package = Views
  dependencies[] = views
  core = 7.x

  files[] = mymodule.module
  files[] = includes/mymodule.views.inc

 ; Information added by drupal.org packaging script on 2011-07-21
  version = "7.x-4.1"
  core = "7.x"
  project = "mymodule"
  datestamp = "1311290520"

In mymodule.module

function mymodule_views_api() {
  return array(
   'api' => 3.0,
   'path' => drupal_get_path('module', 'mymodule') . '/includes',

   );
 }


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

   return array(
    'views_view_field__views__ticker' => array(
    'variables' => array('view' => NULL, 'options' => NULL,'row' =>NULL),
    'template' => 'views-view-field--views--ticker',
    'base hook' => 'views_view_field',
    'path' => drupal_get_path('module', 'mymodule') . '/includes',

         ),
       );
    }

In /mymodule/includes/mymodule.views.inc

  function theme_views_view_field__views__ticker($vars) {

    $view = $vars['view'];
    $field = $vars['field'];
    $row = $vars['row'];

    return $vars['output'];
   }

  function template_preprocess_views_view_field__views__ticker(&$vars)       
   {

    $vars['output'] = $vars['field']->advanced_render($vars['row']);
   }

My custom template file views-view-field--views--ticker.tpl.php in /mymodule/includes

 <?php print $output; ?>

Problem: it is not overriding views-view-field.tpl.php

I am using drupal version 7.41

2
  • do you clean the cache? Jan 18 '16 at 23:47
  • Yes,I did everytime.I believe in my code theme_hook is not propery configured,it is not detecting base hook I guess. Jan 19 '16 at 4:55
-2

You should add the template file on your module info file:

name = My Module
description = Create custom views template.
package = Views
dependencies[] = views
core = 7.x

files[] = mymodule.module
files[] = includes/mymodule.views.inc
files[] = includes/views-view-field--views--ticker.tpl.php

version = "7.x-4.1"
core = "7.x"
project = "mymodule"
datestamp = "1311290520"
4
  • The CVS $Id$ tag hasn't been used by Drupal since the great Git migration in 2011. Likewise, you should never add the stuff that appears below " ; Information added by drupal.org packaging script" to any .info file. That is just wrong and will cause you problems.
    – anonymous
    May 29 '20 at 6:12
  • The question has been formulated with this information in the .info file. So it is not part of the proposed solution.
    – jcarballo
    May 29 '20 at 13:11
  • An answer is supposed to provide the correct solution, so that it may be useful to people other than the original poster. If the original poster knew the correct way to do it, this post wouldn't be here. If you're going to provide an answer you should do your best to ensure it is complete and accurate, and not just repeat the mistakes made by the original poster - you could wind up doing more harm than help when others use your answer verbatim and then run into other problems.
    – anonymous
    Jun 1 '20 at 17:49
  • Thanks you @anonymous!
    – jcarballo
    Jun 2 '20 at 6:47

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.