0

I have a View of taxonomies. I want to rewrite the output of each field (name) as this:

<a href="javascript: void(0);" onClick="alert('[name]');">[name]</a>

so when I click on the taxonomy, it will prompt an alert with the term name.

I try to rewrite through the Views GUI to no avail. I even tried with views_pre_renderbut because there is no #markup property, the rewriting is not HTML but plain text. I did the trick with views_pre_render and other kind of content, but not in taxonomy. And is it really impossible to achieve that in the GUI ? Surely I am missing something very very basic here.

4
  • Do you mean the field label?
    – Jimmy Ko
    Commented Aug 31, 2016 at 8:46
  • The field Taxonomy term: Name . I am reading many post in drupal.org about the case, and cannot believe my eyes. From recommending to use other extra modules, to use PHP Views (a.k.a. the insecure module), and still in 8 it seems the solution is not apparent. We are talking about something extremely basic.
    – Cesar
    Commented Aug 31, 2016 at 8:49
  • 1
    I confirm that it should be a issue in views. But I understand why no one try to fix it. Drupal discourages using onClick. If you want to bind click event, you need to do it with JS behaviors.
    – Jimmy Ko
    Commented Aug 31, 2016 at 9:26
  • Yes, I suspected that. Or binding with jQuery, right? I will go that path. Thank you very much.
    – Cesar
    Commented Aug 31, 2016 at 9:33

1 Answer 1

1

You can do this through theming.

For that you can create a new views-view-field--VIEW_NAME--FIELD_NAME.tpl.php file and write the HTML output for the field.

Dont't forget to clear your cache after adding the file or you can do 'Rescan template files' inside your view.

1
  • I expected not to use tpl, but well, it works.
    – Cesar
    Commented Sep 5, 2016 at 5:18

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.