We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question, Runway

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>
Kirk Roberts

Kirk Roberts 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2637 points
Perch Support

Does it work without the include?

No, so I guess the question should have been "can Blocks be included in a Related tag pair?"

Drew McLellan

Drew McLellan 2637 points
Perch Support

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?):

  • create a collection of sidebar items that have different styling and field needs (some have images, some are giant "buttons" with images and rich text in them, some are blocks of text with inline links, etc).
  • be able to assign these sidebar items to multiple pages
  • the collection means that items can be created once and reused throughout the site, and edited one time in one place with changes reflected throughout the site.
  • multiple items can be assigned to one page

My attempted solution which doesn't seem to work:

  • use a Collection for the sidebar items
  • the Collection template is a Blocks group: one Block type for each type of sidebar item
  • use a Related tag to assign items from the Collection

Does that help with the visualization?

Drew McLellan

Drew McLellan 2637 points
Perch Support

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.

Drew McLellan

Drew McLellan 2637 points
Perch Support

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:

  1. create a repository of items (a Collection) that does not directly display on the site
  2. create a region to dictate which of the repository items appear on the site, and in what order

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.

Drew McLellan

Drew McLellan 2637 points
Perch Support

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.