<p>There's nothing native that would add a column like that, so you'd need to create a plugin or <a href="https://craftcms.com/docs/4.x/extend/module-guide.html" rel="nofollow noreferrer">custom module</a> that registers a custom column by listening to the <code>Asset::EVENT_REGISTER_TABLE_ATTRIBUTES</code> event, and rendering the content for that column (i.e. the list of related entries) via the <code>Asset::EVENT_SET_TABLE_ATTRIBUTE_HTML</code> event.</p>
<p>For that latter part, you'd need to create a query that queries for all entries related to each asset (the asset will be available via the <code>sender</code> attribute for the <code>SetElementTableAttributeHtmlEvent</code> instance passed to your <code>EVENT_SET_TABLE_ATTRIBUTE_HTML</code> event listener); rendering a list of titles/links to each entry (as per your mockup).</p>
<p>The query could probably be an asset query using the <code>relatedTo</code> param, i.e. something like</p>
<pre class="lang-php prettyprint-override"><code>/** @var Asset $asset */
$asset = $event-&gt;sender;

$relatedEntries = \craft\elements\Entry::find()
    -&gt;relatedTo(['targetElement' =&gt; $asset-&gt;id])
    -&gt;all();

...
</code></pre>
<p>...although for performance reasons, you might want to avoid that approach and look into doing a completely custom query.</p>
<p>Here's a complete, albeit simplified (and untested) example of how the solution described above could look (this code would go into your module or plugin's <code>init()</code> method):</p>
<pre class="lang-php prettyprint-override"><code>// Add a custom &quot;Entries&quot; column to asset indexes
Event::on(
    Asset::class,
    Element::EVENT_REGISTER_TABLE_ATTRIBUTES,
    static function (RegisterElementTableAttributesEvent $event) {
        $event-&gt;tableAttributes['_relatedEntries'] = [
            'label' =&gt; 'Entries',
        ];
    }
); 

// Render a list of edit page links for all related entries, for the custom column
Event::on(
    Asset::class, 
    Asset::EVENT_SET_TABLE_ATTRIBUTE_HTML, 
    static function (SetElementTableAttributeHtmlEvent $event) {
        if ($event-&gt;attribute === '_relatedEntries') {
            /** @var Asset $asset */
            $asset = $event-&gt;sender;

            // Get all entries related to this asset
            $relatedEntries = Entry::find()
                -&gt;relatedTo(['targetElement' =&gt; $asset-&gt;id])
                -&gt;all();

            // Build an array of links to the related entries' edit pages
            $entryLinks = [];
            foreach ($entries as $entry) {
                $entryLinks[] = '&lt;a href=&quot;' . $entry-&gt;getCpEditUrl() . '&quot;'&gt;' . $entry-&gt;title . '&lt;/a&gt;';
            }

            $event-&gt;html = implode(', ', $entryLinks);
        }
    }
);
</code></pre>
<p>As a good place to start, I'd also recommend looking at the <a href="https://github.com/born05/craft-assetusage" rel="nofollow noreferrer">Asset Usage plugin</a>, which does <em>almost</em> exactly what you want.</p>

CC BY-SA 4.0
2022-12-06T19:50:37.123Z
Thank you.
But the problem is, that the asset usage plugin doesn't show, on which entry / entries the asset is inserted. I only see how often it is used.
ChuckLean
CC BY-SA 4.0
2022-12-06T20:15:06.133Z
I'm aware, which is why I wrote that the Asset Usage plugin does _almost_ exactly what you want, and that you'll need to implement this as a custom module or plugin. I've added a more complete example to the answer now though – hopefully it'll be useful to you :)
Mats Mikkel Rummelhoff
CC BY-SA 4.0
2022-12-06T18:52:30.477Z
2022-12-06T20:14:22.953Z
2022-12-06T20:14:22.953Z
Mats Mikkel Rummelhoff
<p>Is it possible to display in the asset overview on which entry / entries an asset is used? So that when I go into an asset, I have an overview of the entries where that asset is inserted.<a href="https://i.sstatic.net/pjDtz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pjDtz.png" alt="enter image description here" /></a></p>

<assets><assets-field>
Detect on which entry / entries an asset is inserted
# Detect on which entry / entries an asset is inserted

(Asked by: username_0 on 2022-12-06)

Is it possible to display in the asset overview on which entry / entries an asset is used? So that when I go into an asset, I have an overview of the entries where that asset is inserted.[![enter image description here](https://i.sstatic.net/pjDtz.png)](https://i.sstatic.net/pjDtz.png)

**Tags:** assets, assets-field


---

## 1 answers

### Answer by username_1 on 2022-12-06. Score: 1 | Accepted answer

There's nothing native that would add a column like that, so you'd need to create a plugin or custom module that registers a custom column by listening to the Asset::EVENT_REGISTER_TABLE_ATTRIBUTES event, and rendering the content for that column (i.e. the list of related entries) via the Asset::EVENT_SET_TABLE_ATTRIBUTE_HTML event.
For that latter part, you'd need to create a query that queries for all entries related to each asset (the asset will be available via the sender attribute for the SetElementTableAttributeHtmlEvent instance passed to your EVENT_SET_TABLE_ATTRIBUTE_HTML event listener); rendering a list of titles/links to each entry (as per your mockup).
The query could probably be an asset query using the relatedTo param, i.e. something like
/** @var Asset $asset */
$asset = $event->sender;

$relatedEntries = \craft\elements\Entry::find()
    ->relatedTo(['targetElement' => $asset->id])
    ->all();

...

...although for performance reasons, you might want to avoid that approach and look into doing a completely custom query.
Here's a complete, albeit simplified (and untested) example of how the solution described above could look (this code would go into your module or plugin's init() method):
// Add a custom "Entries" column to asset indexes
Event::on(
    Asset::class,
    Element::EVENT_REGISTER_TABLE_ATTRIBUTES,
    static function (RegisterElementTableAttributesEvent $event) {
        $event->tableAttributes['_relatedEntries'] = [
            'label' => 'Entries',
        ];
    }
); 

// Render a list of edit page links for all related entries, for the custom column
Event::on(
    Asset::class, 
    Asset::EVENT_SET_TABLE_ATTRIBUTE_HTML, 
    static function (SetElementTableAttributeHtmlEvent $event) {
        if ($event->attribute === '_relatedEntries') {
            /** @var Asset $asset */
            $asset = $event->sender;

            // Get all entries related to this asset
            $relatedEntries = Entry::find()
                ->relatedTo(['targetElement' => $asset->id])
                ->all();

            // Build an array of links to the related entries' edit pages
            $entryLinks = [];
            foreach ($entries as $entry) {
                $entryLinks[] = '' . $entry->title . '';
            }

            $event->html = implode(', ', $entryLinks);
        }
    }
);

As a good place to start, I'd also recommend looking at the Asset Usage plugin, which does almost exactly what you want.

> **Comments:**
> **username_0**: Thank you. But the problem is, that the asset usage plugin doesn't show, on which entry / entries the asset is inserted. I only see how often it is used.  
> **username_1**: I'm aware, which is why I wrote that the Asset Usage plugin does _almost_ exactly what you want, and that you'll need to implement this as a custom module or plugin. I've added a more complete example to the answer now though – hopefully it'll be useful to you :)  

---

