3

I have a content type = Article. There I have 2 field. What I want is, If field 1 is empty or does not contain any value, replace this field with field 2, (with same css and html structure) else keep showing content of field 1 by default.

Is there any way to this in D8?

2
  • you have to put some conditions like if field is null then field 2 will show – user52318 Apr 14 '17 at 6:39
  • I don't think you would get any contributed module for such task. But this is easily doable by few lines of code.. – RajeevK Apr 14 '17 at 7:32
3

Create node--articles.html.twig and place it in your theme's templates folder.

{% if content.field_name.0 is empty %}
    <div class="something">{{ content.field_name_other }}</div>
{% else %}
    <div class="something">{{ content.field_name }}</div>
{% endif %}

Note:

0

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.