Show only “Read more” link in drupal 8

2.4k views Asked by At

How can I show only read more link, and remove or unset other links like "add new comments" or "2 Comments" at the end of a node teaser?

1

There are 1 answers

2
Augusto On BEST ANSWER

In order to have custom links, you need the links--node.html.twig template file, it does theme override to display node links.

1. Paste this:

This is links.html.twig talking.... 
{% if links -%}
  {%- if heading -%}
    {%- if heading.level -%}
      <{{ heading.level }}{{ heading.attributes }}>{{ heading.text }}</{{ heading.level }}>
    {%- else -%}
      <h2{{ heading.attributes }}>{{ heading.text }}</h2>
    {%- endif -%}
  {%- endif -%}
  <ul{{ attributes }}>
    {%- for key, item in links -%}
      <li{{ item.attributes.addClass(key|clean_class) }}>
        {%- if item.link -%}
          {{ item.link }}
        {%- elseif item.text_attributes -%}
          <span{{ item.text_attributes }}>{{ item.text }}</span>
        {%- else -%}
          {{ item.text }}
        {%- endif -%}
      </li>
    {%- endfor -%}
  </ul>
{%- endif %}

into your editor

2. Customise at will.

3. save as themes/YOUR_THEME/templates/links.html.twig

4. clear cache

5. See it in action

Thanks for your feedback.