Block template that only brings in assets that have a child image asset.
Craig V 8 years ago in BLOX CMS • updated by Christine Masters (Director of BLOX CMS) 8 years ago • 9
Is there a way to set a block to only include assets that have a child image asset? If not, can this be written in utl? Does anyone have an example?
Customer support service by UserEcho
foreach this.block.assets as asset;
thumb = core_base_library_assetThumb(asset); /* or however you want to assign the thumbnail to a variable */
/* do stuff */
However, since there is a limit to the number of assets a block can pull in a given query, 45 or something like that, you'd be limiting the number of "viable" assets that would qualify to display in your block.
This is a bit inefficient, of course. For example, say you told the block to pull in 20 assets per your query rules, but only 6 of them have child images. You've asked Blox to make that big query and examine all those assets from the database, but you're only using 6 of them. A bit wasteful, but not too bad.
In our next big software release, we are adding two new query rules that are really awesome:
1. Has Preview: This rule will specifically grab the assets that have previews associated to them as part of the query rules. Now, in order to do this, we had to change some of the logic behind the "preview" module. Basically, stories will now be considered to have a preview image if their first child has a preview image. That will then return if you ask a story for asset.preview. Note that we only go one "relationship" deep - so if the story's first child is a collection, and that collection doesn't have a preview, we do NOT go to the collection's children to get one.
You will be able to choose items that have a preview image or do not. This "does not have" rule might be useful in a situation where you want to show the items that have a preview asset in a slideshow block, and the items that DO NOT have a preview image in a headline block.
2. Has Parent: I'm really excited about this one, too. For years, we've artificially restricted most blocks to only allow stories. Mostly, this was because many papers will add section tags to photos and videos and other child elements, causing them to display inside normal story blocks, right next to their parent story. This leads to the appearance of duplicate thumbnails occurring side by side - one from the story showing its child image, and one of the child image showing a thumbnail of itself.
This new "has parent" rule means that you can specifically exclude child assets (no matter what type) from showing up in your main story blocks. Then, you can remove the "type = article" restriction of your story blocks and allow standalone videos and photos to flow naturally within your news blocks.
So, if you had a great video of the bridge demolition, you could file that as breaking news, without having to first associate it with an article.
To me, this means videos, images and even things like table assets now have the capacity to become first-class citizens who can stand on their own alongside stories in any block.
Also, consider a layout where you have several assets at the top that have images in a big display, and then a list of headlines below that for the ones that don't have previews. (i.e. split up the news between items with a preview and those without). For a Calendar page or something, this would be awesome.