2

I want to use a custom function in views-view-fields--field-name.tpl.php template file. Where do I have to put it? Is it possible to use it in template.php in some preprocess functions?

2
  • Add your function in any file and include the file in views-view-field--field_name.tpl.php. Commented Aug 3, 2013 at 11:19
  • You should include the file in views-view-field--field_name.tpl.php using module_load_include. Example : module_load_include('file_type', 'module_name', 'base_file_name'); api.drupal.org/api/drupal/includes!module.inc/function/…
    – Inizio
    Commented Aug 3, 2013 at 22:36

2 Answers 2

4

You can use a preprocess function in your template.php file. For example:

function YOURTHEME_preprocess_views_view_fields__field_name(&$vars) {
  // Do your changes for the field here
}
1
  • call to undefined function it says... Commented Aug 3, 2013 at 18:25
1

In Drupal 7, you can achieve this using module_load_include OR include_once.

  • Create a .inc file in the custom module, which will keep all the template files functions, or if you have only one function then just add the function in your custom module.
  • Go to your template file (views-view-fields--field-name.tpl.php) and include the file using module_load_include() or include_once()
    • If it is a .inc file, use module_load_include('file_type', 'module_name', 'base_file_name');
    • If it is a function in a custom module, use include_once 'FILE_PATH';
1
  • If it is a function in a module, then there isn't any need of using include_once() since every enabled module is loaded when Drupal completes its bootstrap. It's only on early bootstrap phases that the enabled modules are still to be loaded.
    – avpaderno
    Commented Aug 5, 2013 at 6:19

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.