0

I am running into a repeat issue with views and the lack of ability to apply or stick additional classes to a field. We have a "view all content" page that renders fields pertaining to a certain content type and its views through a "Custom Text" field and a variety of excluded fields (so we can render them inside our Custom Text field, to better resemble what the front-end team expects). One of these rendered fields is a hyperlink, and the design team would like to see a class added to it so they can limit a broad set of CSS rules for it.

Okay, simple right? Just go into the field, style settings, and customize its HTML. Done, added classes. But they aren't showing up for this hyperlink. I even tried a more untenable approach of applying a class through a tpl.php rewrite and a Regex. But as long as this field is being displayed through a "Custom Text" field, it does not assign any classes.

The design team has informed me there is no other approach for this given the use of Global Text here. Is there any way to alter what the tokens used by other fields in Drupal output in terms of raw HTML markup, including the addition of other attributes such as classes when taking this design approach?

1

When you use Custom Text, you are telling Views to override anything it does and display only what you have provided it plus the addition of your placeholders. So what you should do here is exclude the original field from the display and write your HTML with the class into the custom text field. Then, include the field placeholder.

Like this.

  <a class="my-class" href="[field_link_url]">[field_link_title]</a>

I am pretty sure this gets you the intended result. Note I am making up those placeholders and you should see what your available replacement patterns are. :)

  • 1
    +1. Those patterns show up when rewriting the link field itself (not for custom text field), so if OP rewrites the link field with those patterns and include the field placeholder in custom text field it should work. Otherwise, OP should add link field twice, once as 'Title as plain text' and second as 'Url as plain text', then two field placeholders will appear in custom text field, ie. [field_link] and [field_link_1] (or something similar depending on what field was named), the one being the title, the other the url. – J. Reynolds Dec 23 '14 at 5:00

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.