<p>You can modify the available table attributes for element indexes using the event <a href="https://docs.craftcms.com/api/v3/craft-base-element.html#event-register-table-attributes" rel="nofollow noreferrer"><code>Element::EVENT_REGISTER_TABLE_ATTRIBUTES</code></a>. You can register that hook in a <a href="https://craftcms.com/docs/3.x/extend/module-guide.html" rel="nofollow noreferrer">custom module</a>. The <code>craft\base\Entry</code> class already has a <code>parent</code> attribute, which will be empty for all top-level and non-structure entries. So all you have to do is to make this attribute available using the hook above:</p>
<pre class="lang-php prettyprint-override"><code>use craft\elements\Entry;
use craft\events\RegisterElementTableAttributesEvent;
use yii\base\Event;

Event::on(
    Entry::class,
    Entry::EVENT_REGISTER_TABLE_ATTRIBUTES,
    function (RegisterElementTableAttributesEvent $event) {
        $event-&gt;tableAttributes['parent'] = [
            'label' =&gt; Craft::t('app', 'Parent'),
        ];
    }
);
</code></pre>
<p>Now the <strong>Parent</strong> column should be available in element indexes for entries. By default, the column will just display the parent's title in the column. If you want to modify that (for example, to display the parent's slug with a link to the parent similar to your screenshot), you can do so using the <a href="https://docs.craftcms.com/api/v3/craft-base-element.html#event-set-table-attribute-html" rel="nofollow noreferrer"><code>Element::EVENT_SET_TABLE_ATTRIBUTE_HTML</code> event</a>:</p>
<pre class="lang-php prettyprint-override"><code>use craft\elements\Entry;
use craft\events\SetElementTableAttributeHtmlEvent;
use yii\base\Event;

Event::on(
    Entry::class,
    Entry::EVENT_SET_TABLE_ATTRIBUTE_HTML,
    function(SetElementTableAttributeHtmlEvent $event) {
        /** @var Entry $entry */
        $entry = $event-&gt;sender;

        if ($event-&gt;attribute != 'parent') return;
        if (!($parent = $entry-&gt;getParent())) return;

        $event-&gt;html = sprintf(
            '&lt;a href=&quot;%1$s&quot;&gt;%2$s&lt;/a&gt;',
            $parent-&gt;getUrl(),
            $parent-&gt;slug
        );
    }
);
</code></pre>

CC BY-SA 4.0
2022-03-10T09:34:31.113Z
2022-03-10T09:34:31.113Z
MoritzLost
<p>I saw <a href="https://craftcms.stackexchange.com/questions/412/can-i-extend-entries-listing-views-currently-or-in-the-future">this older question</a> but it does not appear to work in Craft &gt;=3.x as far as I can tell.</p>
<p>I've got a structure setup with 3 top level pages and some subpages. In this case each top level page will have similarly named subpages.</p>
<p>In the entry listing view for that structure in the control panel if you search for a subpage (one that matches other subpage titles) you have no indication of what its parent is. Originally I thought this was a non-issue and tried to add a 'parent' column to the listing but that is not an option in the customize columns UI.</p>
<p>Here's some screen captures with annotations to better illustrate the issue and my thinking:</p>
<p><a href="https://i.sstatic.net/aqk3x.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/aqk3x.png" alt="enter image description here" /></a></p>
<p>Maybe I need to flip the problem on its head and attack it from another direction altogether though?</p>

CC BY-SA 4.0
2022-03-09T18:09:24.360Z
This _feels_ like you might be approaching your content model from the "wrong" direction (there's no such thing as "wrong" really, just different). I've seen lots of sites, both Craft and EE, where Structure hierarchies have been abused to hold data where the parent and child items are not the same type of thing - it has instead been used as a grouping/categorisation strategy. In those cases, a flat hierarchy with relationships generally works better and is much more flexible. If you could give more detail on the nature of your content model that'll help.
James Smith
CC BY-SA 4.0
2022-03-09T19:31:47.590Z
The idea is to have multiple top level pages that function almost as 'sub-sites' that then have their own children. Each of these would have its own navigation based on it's subpages. Does that make sense?
Bill Columbia
<structure>
How can I see an entries parent in a Structures listing view in the control panel?
# How can I see an entries parent in a Structures listing view in the control panel?

(Asked by: username_0 on 2022-03-09)

I saw [this older question](https://craftcms.stackexchange.com/questions/412/can-i-extend-entries-listing-views-currently-or-in-the-future) but it does not appear to work in Craft >=3.x as far as I can tell.

I've got a structure setup with 3 top level pages and some subpages. In this case each top level page will have similarly named subpages.

In the entry listing view for that structure in the control panel if you search for a subpage (one that matches other subpage titles) you have no indication of what its parent is. Originally I thought this was a non-issue and tried to add a 'parent' column to the listing but that is not an option in the customize columns UI.

Here's some screen captures with annotations to better illustrate the issue and my thinking:

[![enter image description here](https://i.sstatic.net/aqk3x.png)](https://i.sstatic.net/aqk3x.png)

Maybe I need to flip the problem on its head and attack it from another direction altogether though?

**Tags:** structure
> **Comments:**
> **username_1**: This _feels_ like you might be approaching your content model from the "wrong" direction (there's no such thing as "wrong" really, just different). I've seen lots of sites, both Craft and EE, where Structure hierarchies have been abused to hold data where the parent and child items are not the same type of thing - it has instead been used as a grouping/categorisation strategy. In those cases, a flat hierarchy with relationships generally works better and is much more flexible. If you could give more detail on the nature of your content model that'll help.  
> **username_0**: The idea is to have multiple top level pages that function almost as 'sub-sites' that then have their own children. Each of these would have its own navigation based on it's subpages. Does that make sense?  

---

## 1 answers

### Answer by username_2 on 2022-03-10. Score: 2 | Accepted answer

You can modify the available table attributes for element indexes using the event Element::EVENT_REGISTER_TABLE_ATTRIBUTES. You can register that hook in a custom module. The craft\base\Entry class already has a parent attribute, which will be empty for all top-level and non-structure entries. So all you have to do is to make this attribute available using the hook above:
use craft\elements\Entry;
use craft\events\RegisterElementTableAttributesEvent;
use yii\base\Event;

Event::on(
    Entry::class,
    Entry::EVENT_REGISTER_TABLE_ATTRIBUTES,
    function (RegisterElementTableAttributesEvent $event) {
        $event->tableAttributes['parent'] = [
            'label' => Craft::t('app', 'Parent'),
        ];
    }
);

Now the Parent column should be available in element indexes for entries. By default, the column will just display the parent's title in the column. If you want to modify that (for example, to display the parent's slug with a link to the parent similar to your screenshot), you can do so using the Element::EVENT_SET_TABLE_ATTRIBUTE_HTML event:
use craft\elements\Entry;
use craft\events\SetElementTableAttributeHtmlEvent;
use yii\base\Event;

Event::on(
    Entry::class,
    Entry::EVENT_SET_TABLE_ATTRIBUTE_HTML,
    function(SetElementTableAttributeHtmlEvent $event) {
        /** @var Entry $entry */
        $entry = $event->sender;

        if ($event->attribute != 'parent') return;
        if (!($parent = $entry->getParent())) return;

        $event->html = sprintf(
            '%2$s',
            $parent->getUrl(),
            $parent->slug
        );
    }
);


---

