1

I am trying to add custom attribute with elements like "data-url" and "data-text" in views fields, it shows something like "data-text="test text"> as output on front end. How can i add them so that they work as attribute and not print as text ?

1 Answer 1

1

It's not initially obvious where and how to make these changes, fortunately it's not too hard to rewrite the output of the fields in views.

You can make a new views template fields from the display:

Other > Theme:Information link

Then edit the code adding your HTML around the Php and dropping it into your theme templates folder.

Or another way which I find is a lot quicker especially when there is a lot of changes going on in a development of a site, use the global custom text field or write the content fields.

I will use the title field to add an attribute as an example for you to follow.

In your view:

*edit Fields > title*

*Rewrite results >* tick *Rewrite the output of this field*

In the text field add the following code using the tokens options provided and editing your HTML to your requirements.

<h2 class"yourclass" data-text="test text">[title]</h2>

Save the view and you will see your attributes in your Views display.

To add to this if you use the field Global text you can hide each of your fields then rewrite the HTML to whatever you need to, adding HTML for each token in the row.

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.