%asset_parent% keyword for linked items in an asset listing


(Tom Stringer) #1

According to the manuals, the %asset_parent% keyword “Returns the current parent asset ID based on the current asset in its lineage context.”

I have a single asset (#1111) linked into three different folders (#2222, #3333, #4444).

I’m listing each of the assets in those folders with an Asset Listing. In the Default Format of the asset listing I’m using: %asset_assetid% - %asset_parent%

My reading of the %asset_parent% keyword suggests that I should get:

1111 - 2222
1111 - 3333
1111 - 4444

But what I actually get is:

1111 - 4444
1111 - 4444
1111 - 4444

Is that a bug, or am I doing something wrong?


(Bart Banda) #2

The current context is based on the current frontend URL you are viewing. You would get the same result if you used %asset_url%, you would get the same value for all 3 (I’m 99% sure).

If you want information about all of the possible parents and then choose which one to print based on your own context rules, you could try using %asset_parents% (with maybe ^as_asset:asset_url% or something similar) and feed it through some SSJS to then decide which of them to print?


(Tom Stringer) #3

Thanks Bart

Interesting. We’ve actually found that the best solution in this particular instance is to use %root_nodes% in place of %asset_parent% - that gives us the immediate folder of the individual assets which is what we need here.


(Tom Stringer) #4

An update to this one. %root_nodes% works because we were using two asset lists. The first returned parent folders, the second returned the Data Assets in those folders. In that context %root_nodes% referred to the parent folder so worked as we wanted.

We’ve since updated this so that we’re just using a single asset listing to list the Data Records, but that means %root_nodes% now returns an array of IDs for a given asset instead of printing each separately with its associated parent in context - back to square one.

Under these circumstances we end up with something that looks like:

1111 - 2222, 3333, 4444

We were able to get them printing separately by using a level 1 folder grouping which got us back to:

1111 - 2222
1111 - 2222
1111 - 2222

Same problem as in the original. The question is how to retrieve the right parent for the asset in context.

In this case, the relevant parent would be the grouping that the asset is being printed within, but there’s no %asset_parent_grouping% keyword to do this easily from the Default Format bodycopy. In the Group Format bodycopy you can use %parent_assetid% to retrieve the ID of the current group - this is exactly what we want.

The solution here was to use SSJS in the Group Format bodycopy to assign the %parent_assetid% value to a SSJS variable and then to print that variable from the Default Format bodycopy.

Group Format bodycopy:

<script runat="server">var id = "%parent_assetid%";</script>%group_listing%

Default Formart bodycopy:

%asset_assetid% - <script runat="server">print(id);</script>

The result is:

1111 - 2222
1111 - 3333
1111 - 4444

Thought it might be worth recording this in case others have the same trouble.