3

As shown in the picture, I have the teaser view of a taxonomy term (Virtual Tour) which shows the node title, the node summary, the submission date, and an image added in an image field.

What I would like to achieve is to let the image float to the left of the summary. Is there a way to achieve it?

screenshot

3 Answers 3

5

The teaser view mode display is controlled on the display modes of the given entity type, in this case, node. You can control the field order and formatters used there, and other modules like Display Suite can enhance the options here.

With that, you can also provide a twig template to change the markup and classes of this view mode being displayed for the node. From there, you can style it all you want once you have the markup and fields the way you want them.

More:

7

You should already have a template suggestions available like :

<!-- FILE NAME SUGGESTIONS:
   * node--2--teaser.html.twig
   * node--2.html.twig
   x node--BUNDLE--full.html.twig
   * node--BUNDLE.html.twig
   * node--teaser.html.twig
   * node.html.twig
-->

Make sure you have settings.yml set to twig.config: { debug: true ... and you will see the suggestions in the source. You can set suggestions for any hook like:

function MODULE_theme_suggestions_node_alter(array &$suggestions, array $variables, $hook) {
 $node = $variables['elements']['#node'];
 $type = $node->bundle();
 $view_mode = $variables['elements']['#view_mode'];

 $suggestions[] = 'node__'.$type;
 $suggestions[] = 'node__'.$type.'__'.$view_mode;
}
0

In the template file, you can render the teaser in view mode.

{% if view_mode == 'teaser' %}
  <!-- Start Display article for teaser page -->
  <div class="portfolio-v1">      
    {{ content.field_some_portfolio_images }}
  </div>
{% elseif view_mode == 'teaser_2' %}
  <!-- Start Display article for teaser 2 page -->
  <div class="portfolio-v2">      
    {{ content.field_some_portfolio_images }}
  </div>
{% else %}
  <!-- Start Display article for detail page -->
  <article{{ attributes.addClass(classes).addClass('node-detail') }}>
    <div class="post-block portfolio-single">
      {% if content.field_some_portfolio_images %}
        {{ content.field_some_portfolio_images }} 
      {% endif %}
    </div>
  </article>
{% endif %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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