Component Template attribute


#1

I am attempting to use a search asset to return Component type assets. It does return them ok, but I want to be able to

a) not include any in the search that do not have a Component Template assigned
b) be able to search by what Component Template they ahve assigned.

Clearly a Component knows what template to use when it is being displayed, but is that attribute available to both output and search on?


(Iain Simmons) #2

Hi @moolric,

The assigned template is normally more of an internal thing, but you can access it via this keyword:

%asset_data_attributes^index:attributes^index:value^index:template%

That would give you the asset ID of the template applied to the Component.

If you wanted, say, the name of the template, you would have to further chain on an ^as_asset modifier like so:

%asset_data_attributes^index:attributes^index:value^index:template^as_asset:asset_name%

Unfortunately, that only helps to display the applied template, from an asset listing or search page. To actually search it, I think you would need to add a text metadata field to every Component and then the default value could be that keyword. I’m not 100% sure that would work though, and you might even need to go as far as using triggers to set that value if and when the applied template is changed for a Component.

All that being said, does the Usage screen of the Component Template asset give you the information you are looking for?

– iain