Get attribute from Tailor block

My pages are build with mixin, one of them is called hero.
On the parent page I want to show sub pages but I want to show the image of the subpage.

How do I get the image properly out of the array?

{% for block in children.blocks %}
    {% if block.type == 'hero' %} 
       {# {{ block.attributes.media }} #} {# shows an array of image(s), see array below #}
       {# <img src="{{ block.attributes.media[0[|media }}"> #} {# not working, no output #}
       {% for value in block.attributes.media %}
            {{ value }} {# not working, no output #}
       {% endfor %}
    {% endif  %}                
 {% endfor %} 
["\/images\/weddings\/tanya-jack-september-2023-third-wheeling-co-ceremony-4.jpg"]
Tailor\Models\RepeaterItem {#2145 ▼
  #connection: "mysql"
  #table: "xc_ed2e03055eeb46549daf0cc89f7961d8r"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  +preventsLazyLoading: false
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #escapeWhenCastingToString: false
  #attributes: ?
  #original: array:20 [▶]
  #changes: []
  #casts: []
  #classCastCache: []
  #attributeCastCache: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: array:1 [▶]
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: array:9 [▶]
  #guarded: array:1 [▶]
  +implement: null
  +attributes: array:20 [▼
    "title" => "Example Title"
    "highlight" => ""
    "content" => "Test content"
    "header" => "h1"
    "media_alt" => "test-image-2"
    "list_items" => "[[]]"
    "button_url" => ""
    "button_text" => ""
    "media" => "["\/images\/test-image-2.jpg"]"
    "id" => 43
    "host_id" => 10
    "host_field" => "blocks"
    "site_id" => null
    "content_group" => "hero"
    "content_value" => "
{"title":"Example Title","highlight":"title","content":"Test Content
 ▶
"
    "content_spawn_path" => "Tailor\Models\EntryRecord@ed2e0305-5eeb-4654-9daf-0cc89f7961d8.blocks:hero"
    "parent_id" => null
    "sort_order" => 1
    "created_at" => "2024-05-09 22:54:28"
    "updated_at" => "2024-05-11 01:55:25"
  ]
  #savingOptions: []
  +trimStrings: true
  #jsonable: array:3 [▶]
  +hasOne: []
  +hasMany: []
  +belongsTo: []
  +belongsToMany: []
  +morphTo: array:1 [▶]
  +morphOne: []
  +morphMany: []
  +morphToMany: []
  +morphedByMany: []
  +attachOne: []
  +attachMany: []
  +hasManyThrough: []
  +hasOneThrough: []
  #emitterSingleEventCollection: []
  #emitterEventCollection: array:7 [▶]
  #emitterEventSorted: array:1 [▶]
  #extensionData: array:4 [▶]
  +sessionKey: null
  #expandoColumn: "content_value"
  #expandoPassthru: array:10 [▶]
  +rules: []
  #fieldsetConfig: array:14 [▶]
  #useFieldsetGroups: true
  #isBlueprintExtended: true
  #isLazyLoadedRelation: []
  +validationForced: false
  #validationErrors: null
  #validationDefaultAttrNames: []
}

change to

{% for image in block.media %}
            <img src="{{ image|media }}"/>
       {% endfor %}

may be you must change this

{% for block in children.blocks %}

to

{% for block in your_section_name.blocks %}

It was this change.

{% for image in block.media %}
  <img src="{{ image|media }}"/>
{% endfor %}
1 Like