0

In a view I need to add a custom data-attribute to the row output (just like classes are added). Simply rewriting the output doesn't work because XSS attribute filtering strips the attribute. How can I accomplish this in a reasonable way? These answers are for D7 and do not quite cover dynamic output:

Custom attribute in views fields

How to add data attributes to view list <li> tags?

2
  • 1
    How are you trying to Rewrite, with what code? I haven't noticed any stripping of the attribute, maybe it's only your value missing?
    – prkos
    Commented May 7, 2019 at 21:59
  • Oh man, you are right, it was a missing value! When things didn't work, I started research, found out that the style attribute is stripped in views when rewriting and stumbled upon drupal.org/project/views/issues/417956 – so I concluded, the attribute is stripped as well. Thanks!
    – Madam Adam
    Commented May 8, 2019 at 8:16

1 Answer 1

1

To summarize for future reference:

You can add data attributes using Rewrite in Views Fields.

If you added a custom data-attribute but something isn't working, the problem might be in the value ;)


What gets stripped by the filter_xss_admin() on Rewrite is most notably the <object> tag and style="" attribute because users can submit malicious code through those.

It seems Views for D7 will have that check removed in the next release: Remove filter_xss_admin() from result rewriting because views editors are already trusted admins

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.