twig-tips

Declare all variables first

This allows you a better defense against what is being passed through.

And give you an opportunity to set defaults.

It also provides more clarity and a little separation between data and markup.

{# _news/index.twig #}

{% for entry in craft.entries({
    section: "news",
    limit: 10,
}).all() %}
    <div>
        {% include "_components/card" with {
            image: entry.listingImage.one(),
            heading: entry.title,
            description: entry.description,
        } only %}
    </div>
{% endfor %}
{# _components/card.twig #}

{% set image = image ?? null %}
{% set heading = heading ?? "Lorem ipsum dolor sit amet" %}
{% set description = description ?? null %}

<div>
    {% if image %}
        <img src="{{ image }}" alt="">
    {% endif %}
    <h3>{{ heading }}</h3>
    {{ description }}
</div>