2

On my template I am using the following to define a og:meta image url, some pages will override this.

<meta property="og:image" content="{% block ogMetaImage %}{% endblock %}" />

Now, what I want to do is have a default image there if the block is not set on one of my child pages that extend my main template.

Something like the following should be on the main template

<meta property="og:image" content="{% block ogMetaImage%}https://example.com/image.jpg{% endblock %}" />

Is there a way to do this with Twig?

Joe Scotto
  • 8,050
  • 7
  • 41
  • 100

1 Answers1

3

It's just like u described in your question actually.

main.twig

{% block foo %}
    Foo
{% endblock %}

bar.twig

{% extends "main.twig" %}
{% block foo %}
     Bar
{% endblock %}

Output: bar

foobar.twig

{% extends "main.twig %}

Output: foo

DarkBee
  • 13,798
  • 5
  • 41
  • 53