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 Commented Apr 14, 2017 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.. Commented Apr 14, 2017 at 7:32

1 Answer 1

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.