0

Apologies if there is a good documentation out there, I searched and read other topics for over 30 minutes now, could not figure it multiple things with theming a field.

My objective is to customize a field inside a views called field_calendly_url. I found the following field template. I have several questions;

  1. Would I need to make changes with set classes, for example change field--name- to field--calendly--url?
  2. How can print my field value, I tried {{ field.calendly.url }} and {{ fields.calendly.url }} but neither worked.
  3. Do I have to keep the if statement for label even if I am not using a label?

` {% set classes = [ 'field', 'field--name-' ~ field_name|clean_class, 'field--type-' ~ field_type|clean_class, 'field--label-' ~ label_display, ] %} {% set title_classes = [ 'field--label', label_display == 'visually_hidden' ? 'sr-only', ] %}

{% if label_hidden %}
  {% if multiple %}
    <div{{ attributes.addClass(classes, 'field--items') }}>
      {% for item in items %}
        <div{{ item.attributes.addClass('field--item') }}>{{ item.content }}</div>
      {% endfor %}
    </div>
  {% else %}
    {% for item in items %}
      <div{{ attributes.addClass(classes, 'field--item') }}>{{ item.content }}</div>
    {% endfor %}
  {% endif %}
{% else %}
  <div{{ attributes.addClass(classes) }}>
    <div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div>
    {% if multiple %}
      <div class="field--items">
    {% endif %}
    {% for item in items %}
      <div{{ item.attributes.addClass('field--item') }}>{{ item.content }}</div>
      hello...
    {% endfor %}
    {% if multiple %}
      </div>
    {% endif %}
  </div>
{% endif %}

<a href="javascript:void jQuery.colorbox({html:'<iframe width=400 height=400 src={{ field.calendly.url }} {{ fields.calendly.url }} frameborder=0 allowfullscreen></iframe>'})" class="btn-box">Request Meeting</a>

`

1

In case anyone else will look for this later, I was able to display the views field value with the following.

{{ view.field.field_calendly_url.original_value }}
0

This answer assumes that the template in your question is the correct field template for your view.

  1. You can use whatever classes you want. Views provides a bunch of classes by default, but these classes are just that-- default classes to make it easier for people to theme without having to customize the templates. You can ignore them, remove them, replace them with whatever you want.

  2. Usually the field value is printed with item.content. If this is the correct template, you should already see it as output in your view.

  3. No, you don't need to keep the code for the label. However, if you delete it, you may later forget you deleted it and then set a label in the Views UI, but it will never appear, and this could be confusing because it is disabled in the template.

PS: In the future, try to keep to one question per question on this site. Asking multiple questions is likely to get your question closed as unclear.

2
  • Patrick thank you for all the answers. I think it is the correct class because my link replaces the field. But {{ item.content }} does not return the field value.
    – user102319
    Feb 4 at 22:55
  • FYI, its a link field.
    – user102319
    Feb 4 at 23:03

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.