{# VARIABLES #}
{% set type = type|default('fg') %}
{% set img_attributes = img_attributes|default(create_attribute())
  .setAttribute("src", file_url(url))
  .setAttribute("alt", alt|default("Image alt text"))
%}

{# TEMPLATES #}
{% if type == 'fg' %}

  {%- set image -%}
    {% if url is not empty %}
      <img {{ img_attributes.addClass(img_class|default("")) }}/>
    {% else %}
      {{- image -}}
    {%- endif -%}
  {% endset %}

  {% include '@atoms/html5/image/_image--image.twig' with {
    image: image,
    caption: caption
  } only %}

{% elseif type == 'bg' %}

  {% include '@atoms/html5/image/_image--background.twig' with {
    url: url,
    background_class: background_class,
    caption: caption
  } only %}

{% endif %}
