Forum
Can a template include with blocks be used in a Related tag pair?
Is this template code legal in Perch Runway 2.8.8?
<perch:related id="sidebar_items" collection="Sidebar Items" label="Sidebar Item">
<perch:template path="content/sidebar_items_collection.html" rescope="parent" />
</perch:related>
The template has blocks in it, and nothing displays on the front end after I've added some relations. It's the same template as is used to create the related Collection.
I know the items are saved because I can access the variables directly like this:
<perch:related id="sidebar_items" collection="Sidebar Items" label="Sidebar Item">
<perch:content id="_title" />
</perch:related>
Does it work without the include?
No, so I guess the question should have been "can Blocks be included in a Related tag pair?"
Is the related item built with blocks?
I'm struggling to visualise how this would work!
Sorry, yes it's blocks. Here's the goal (maybe there's a better way to achieve it?):
My attempted solution which doesn't seem to work:
Does that help with the visualization?
It does, but doesn't get us to a solution. It's almost like you need a way to pull in the resulting HTML output of that item rather than the blocks themselves.
Right, that's what I thought would happen... that including the template code (in this case, blocks) would produce the HTML output. I'm sure there are "under the hood" things going on I don't understand yet, but it makes sense to me that if other perch tags and html can be included in a Related tag pair then blocks should be allowable there as well. Maybe that hadn't been considered as a use case before.
Realizing a limitation with this approach: it doesn't seem that items can be reordered in a Related field. Technically they can be removed and re-added in whatever order is desired, but that order doesn't seem to be reflected in the output (seems to be the order specified in the Collection options).
Edit: actually, upon Save, the items in the Related field are reordered in the Perch control panel.
Ordering of related items is something on my to-do list.
Great on the ordering. I'm working on a site with three instances where that's needed. The pattern is the same for all three:
Still wondering about the ability to use Blocks inside Related tag pairs.
In this case I've reverted to using regular Shared regions, Repeaters with Data Select fields, and some PHP to loop and produce the template output.
You can't currently use blocks in related fields. I can't foresee how that would work, other than the cached HTML approach I mentioned.
I'm a little surprised "blocks in related fields" hasn't been brought up or requested before. There are probably all kinds of technical considerations behind the scenes, but I'm ignorant enough to think it would just work because content is content, right? (rhetorical question to prove my ignorance)
This is my first Runway build, so I don't know if there is a better way to accomplish the data pattern I mentioned with Runway tools (collections, related fields, etc). I guess the old way I mentioned in my previous reply still works fine.