getUrl() not working I have the following code in the “main.twig” template:

&lt;head&gt;
    {% block head %}
        &lt;meta property="og:image" content="{% block pageImage %}{% endblock %}" /&gt;
    {% endblock %}
&lt;/head&gt;


Then, I’m trying to populate the image URL into the &lt; meta > tag from a Matrix field:

{% extends "templates/main" %}
{% for block in entry.articleBody %}
    {% if block.type == "articleImage" %}
        {% set image = block.articleImage.first().getUrl() %}
        {% block pageImage %}{{ image }}{% endblock %}
    {% endif %}
{% endfor %}
{% block head %}{{ parent() }}{% endblock %}


However, no URL is outputted. Does anyone know why?

Thanks!
Twig generally doesn't like nested/un-nested blocks like this. A better way to deal with this would be to just set a variable; and since twig renders templates from the inside-out, any variables that you define in child-templates should be available to the parent.

So in 'main.twig':

&lt;head&gt;
    &lt;meta property="og:image" content="{% if seoImage is defined %}{{ seoImage }}{% endif %}" /&gt;
&lt;/head&gt;


And in your child-template:

{% extends "templates/main" %}

{# note: needs to be defined outside the 'for' loop to become available #}
{% set seoImage="" %} 
{% for block in entry.articleBody %}
    {% if block.type == "articleImage" %}
        {% set seoImage = block.articleImage.first().getUrl() %}
    {% endif %}
{% endfor %}


You can still use blocks of course in addition to this technique, but generally best to keep them in the same nesting order.

On a side-note: I don't think you need the 'templates/' part of the extends statement (unless you have a 'templates' folder inside 'templates'). Normally you would just use {% extends "_main" %}. The underscore in the name also prevents the template from being loaded directly.