1

I am using the latest version of drupal and trying to assign my custom created template to a view. I have created a view with machine name designers and followed this article to create custom template for a view. I place the view files inside core > profiles > demo_umami > themes > umami > templates > views folder.

Here is the code of the file views-view-fields--designers--page.html.twig

{#
/**
 * @file
 * Default view template to display all the fields in a row.
 *
 * Available variables:
 * - view: The view in use.
 * - fields: A list of fields, each one contains:
 *   - content: The output of the field.
 *   - raw: The raw data for the field, if it exists. This is NOT output safe.
 *   - class: The safe class ID to use.
 *   - handler: The Views field handler controlling this field.
 *   - inline: Whether or not the field should be inline.
 *   - wrapper_element: An HTML element for a wrapper.
 *   - wrapper_attributes: List of attributes for wrapper element.
 *   - separator: An optional separator that may appear before a field.
 *   - label: The field's label text.
 *   - label_element: An HTML element for a label wrapper.
 *   - label_attributes: List of attributes for label wrapper.
 *   - label_suffix: Colon after the label.
 *   - element_type: An HTML element for the field content.
 *   - element_attributes: List of attributes for HTML element for field content.
 *   - has_label_colon: A boolean indicating whether to display a colon after
 *     the label.
 *   - element_type: An HTML element for the field content.
 *   - element_attributes: List of attributes for HTML element for field content.
 * - row: The raw result from the query, with all data it fetched.
 *
 * @see template_preprocess_views_view_fields()
 *
 * @ingroup themeable
 */
#}
<h2> Coming in the template </h2>
{% 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 %}

Here is the content of views-view--designers--page-1.html.twig

{#
/**
 * @file
 * Default theme implementation to display a view of unformatted rows.
 *
 * Available variables:
 * - title: The title of this group of rows. May be empty.
 * - rows: A list of the view's row items.
 *   - attributes: The row's HTML attributes.
 *   - content: The row's content.
 * - view: The view object.
 * - default_row_class: A flag indicating whether default classes should be
 *   used on rows.
 *
 * @see template_preprocess_views_view_unformatted()
 *
 * @ingroup themeable
 */
#}
<h2> Coming in the Template</h2>
{% if title %}
  <h3>{{ title }}</h3>
{% endif %}
{% for row in rows %}
  {%
    set row_classes = [
      default_row_class ? 'views-row',
    ]
  %}
  <div{{ row.attributes.addClass(row_classes) }}>
    {{- row.content -}}
  </div>
{% endfor %}

When i load the page in browser i.e http://localhost/drupal/designers i am not getting the text i added in the template files.

Can anyone help me how i can show the html content which i added in the view files on the page http://localhost/drupal/designers.

I have spent 3 days and still not able to show the content on the page.

Thanks in advance.

  • Hi and welcome to Drupal Stackexchange. First of all, you should never place your template files under the core folder. Second thing, which theme are you using? In case you are editing a theme, you should create a child theme for it and then you should place your template files under the templates folder of that child theme as per the article you referenced. – Ismail Cherri Mar 15 at 12:46
  • Thanks a lot for warm the welcome. Actually i placed the file under core folder because i checked the theme path and it was from the core > profiles > demo_umami > themes > umami > templates . I imported a demo site while installing drupal. The theme i am using is umami. – Developer Mar 15 at 12:53
  • You should create a child theme and then place your template files there – Ismail Cherri Mar 15 at 13:39
  • okay let me do that and i will come back here. Thanks – Developer Mar 15 at 13:55

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.