0

I'm using views-view-fields.html.twig to display content. I can print the file name using fields.field_module_field_name.content, but the code below outputs not only the file name, but also the path to where it's stored (It also displays the other fields in the module). I'm trying to take the path and set it as an href to the document for viewing/downloading.

I was tasked to complete this module.Everything about it is dynamic, so I need to be as generic as possible. Let me know how if more information is needed. I'll try my best to provide them.

{% for field in fields -%}
  {{ field.separator }}
  {%- if field.wrapper_element -%}
    <{{ field.wrapper_element }}{{ field.wrapper_attributes }}>
  {%- endif %}
  {%- if field.label -%}
    {%- if field.label_element -%}
      <{{ field.label_element }}{{ field.label_attributes }}>{{ field.label }}{{ field.label_suffix }}</{{ field.label_element }}>
    {%- else -%}
      {{ field.label }}{{ field.label_suffix }}
    {%- endif %}
  {%- endif %}
  {%- if field.element_type -%}
    <{{ field.element_type }}{{ field.element_attributes }}>{{ field.content }}</{{ field.element_type }}>
  {%- else -%}
    {{ field.content }}
  {%- endif %}
  {%- if field.wrapper_element -%}
    </{{ field.wrapper_element }}>
  {%- endif %}
{%- endfor %}

Sample output above would be in the following format.

status, title, date and time, file name, file path

Your Answer

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

Browse other questions tagged or ask your own question.