Retrieving a keyword from asset generated via Paint Layout and Asset Listing


(Ryan Archer) #1

I'm trying to make a side menu that knows the parent category of the page being viewed. What I currently have is a mixture of Paint Layouts, Asset Listings, Category Folders and News Items to create something similar to a 'Blog'.

 

A combination of the Paint Layout and Asset Listing is what makes up the screen content when viewing a News Item. Currently I am able to retrieve the name of the News Item asset by using the $asset_name% keyword replacement in the paint layout that generates the News Item's contents.

 

Each of the News Items are created within a folder asset which acts as a category. What I want to do with the menu (using the EasyTree Menu js) is have Squiz tell me what the parent category is of the News Item currently being viewed - store this as a variable that is passed to the EasyTree menu js at runtime so that it will have all category folders contracted except for the category that the current item being viewed is within. Pretty much making it a smart menu.

 

My issue is that I cannot get the asset's parent name. It would seem I can only use the %parent_name% keyword on a Group Format Bodycopy http://manuals.matrix.squizsuite.net/keyword-replacements/chapters/asset-listing

 

Seeing as though I am using this Keyword Replacement on a Paint Layout bodycopy, I just don't know how to get the name of the parent folder. Is there a possible way to do this? The closest thing I could find is to get the %asset_lineage% and then using .replace() method to cut out the unecessary text in the string, sounds messy when I come to think of it.

 

Hopefully there is a better way??


(Nic Hubbard) #2

An asset could have many many parents (if you link it in multiple locations), so this can pose an issue for your question. However, if there is only one parent, you can create an Asset Listing that looked UP the tree one level (direct links only set to Yes). Set the Dynamic Params to current asset, then nest that Asset Listing in the paint layout. That will tell you what the parent is.


(Ryan Archer) #3

Thanks Nic, I had a go at that but it did not work out for me, I got no results from the asset listing. Just to clarify the process:

 

1) Create an asset listing page (which I just placed in my "components" folder)

2) Nest that asset listing page into the paint layout which displays the content for the News Item ("News Item Format" bodycopy)

3) Go back to the newly created asset listing page and then call up the javascript function: alert ("%asset_name%"); on the "default format" bodycopy?

 

I am just getting the "no results were found" message and no javascript alert action.

 

I'm not sure what's going on here, did you want me to PM with more visual information?


(Ryan Archer) #4

For now, I'm just splitting the string returned with Javascript.

The folders will always be in the same place and the News Items will always be within one of the folders so although it could be considered a 'string hack', its risk is controlled and minimized.

 

https://jsfiddle.net/coolwebs/2j56cva0/7/


(Nic Hubbard) #5

Thanks Nic, I had a go at that but it did not work out for me, I got no results from the asset listing. Just to clarify the process:

 

1) Create an asset listing page (which I just placed in my "components" folder)

2) Nest that asset listing page into the paint layout which displays the content for the News Item ("News Item Format" bodycopy)

3) Go back to the newly created asset listing page and then call up the javascript function: alert ("%asset_name%"); on the "default format" bodycopy?

 

I am just getting the "no results were found" message and no javascript alert action.

 

I'm not sure what's going on here, did you want me to PM with more visual information?

 

You missed three important steps. Set Tree direction to "Up the Tree", and set Direct Links to Yes. You also need to set the Dynamic Params to the Current Asset.


(Ryan Archer) #6

Yeah I did all what you said, sorry I just got lazy to type it.

Nesting is doing my head in. I got what I wanted with JS instead of creating more assets in my site (which is already so full of them as it is).

 

Here is what I did, I put the following JS into the Paint Layout (that's applied to the asset listing) that generates the News Item Content:

 

<script>

var lineageName = “%asset_lineage%”;

var pathDir = lineageName.split(">");
alert(“You are viewing this item in the category of”+pathDir[2]);

</script>

Now I got the variable I want. Time to play...