I have tried to set the value of variables in several hooks, but although these hooks are called, the value is not passed to the views template file.

Does anyone know where to define a custom variable to be used in the views template?

  • Can you give a little more detail as to what you are trying to accomplish. In some circumstances it might be as easy as adding another field to your view and just not displaying it ... but that largely depends on what you are really trying to do – bleen Sep 1 '16 at 15:40
  • Also, it depends from which hooks you are using. A template file doesn't get values from every hook Drupal runs. – kiamlaluno Sep 1 '16 at 16:18
  • I have a configuration form, where I can set some values, for example number of items per row and other values that I need. I've been using the values of these variables setting them in a hook, but when I try to access them from the template for a view, they are empty. The hook I've tried are hook_preprocess_views_view and hook_preprocess_page. BTW is a Drupal 8 installation. – jmzea Sep 1 '16 at 17:30

Your Answer

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

Browse other questions tagged or ask your own question.