Forum

Thread tagged as: Question, Runway

Collection and block template

When I create a collection with a block template it doesn't allow me to sort each entry on title and date. The issue probable is because I use the block template for this, but is there a way to get this done?

What I want to do is make it possible to create different style of posts. For example post 1 will be a standard article. Post 2 will be an image (full with or half with a description), etc.

So basically I want to create post with a different template. (a selection of post types)

Robin Gruyters

Robin Gruyters 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

How are you trying to sort it?

Tried on "_title, date" and "title, date" and even "heading, date". None work.

Although as I'm typing this I think I know what the problem is.

<perch:blocks>
  <perch:block type="article" label="Article">
    <perch:template path="content/articles/article.html" />
  </perch:block>

  <perch:block type="image" label="Pictures">
    <perch:template path="content/_blocks/image.html" />
  </perch:block>
</perch:blocks>

At the moment each template include has his own Heading and Date to set. I probable need to move this out of each template and set it inside the <perch:blocks></perch:blocks> statement.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can't sort on multiple fields, just one.

Which is the best way to do this? Move Heading & Date outside the <perch:blocks></perch:blocks> elements?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me the code that's failing?

Sure!

At the moment I still have the following:

posts.html

<perch:blocks>
  <perch:block type="article" label="Article">
    <perch:template path="content/articles/article.html" />
  </perch:block>

  <perch:block type="image" label="Pictures">
    <perch:template path="content/_blocks/image.html" />
  </perch:block>
</perch:blocks>

article.html

<article class="post h-entry">
  <header class="post--header">
    <h2 class="p-name"><perch:content id="heading" type="text" label="Heading" required="true" title="true" /></h2>
    <time datetime="<perch:content id="date" type="date" label="Date" format="%d-%m-%Y" required="true" />" class="post--date dt-published"><perch:content id="date" type="date" label="Date" format="%d %B %Y" require="true" /></time>
  </header>

  <perch:if exists="summary">
  <section class="post--excerpt">
    <perch:content id="excerpt" type="textarea" label="Excerpt" markdown="true" editor="markitup" />
  </section>
  </perch:if>

  <section class="post--body">
    <perch:content id="body" type="textarea" label="Body" markdown="true" editor="markitup" required="true" />
  </section>
</article>

image.html

<article class="post h-entry">
  <header class="post--header">
    <h2 class="p-name"><perch:content id="heading" type="text" label="Heading" required="true" title="true" /></h2>
    <time datetime="<perch:content id="date" type="date" label="Date" format="%d-%m-%Y" required="true" />" class="post--date dt-published"><perch:content id="date" type="date" label="Date" format="%d %B %Y" require="true" /></time>
  </header>

  <figure>
    <img src="<perch:content id="image" type="image" width="1600" label="Image" />" />
  </figure>
</article>

I have tried to move the "heading" and "date" outside the blocks element and that works fine in the overview. Only I need to find to include it in each article element.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What code are you using on your page? That's where the sorting is happening, isn't it?

Don't have yet coded for a page. Currently developing locally and testing what is possible.

The sorting I have done is in Perch itself. At the moment I see item with "Item 1", "Item 2", etc.

I haven't tested this but I think I have to do something like this:

<perch:content id="heading" type="text" label="Heading" required="true" title="true" suppress="true" />
<perch:content id="date" type="date" label="Date" format="%d-%m-%Y" required="true" suppress="true" />

<perch:blocks scope-parent="true">
  <perch:block type="article" label="Article">
    <perch:template path="content/articles/article.html" />
  </perch:block>

  <perch:block type="image" label="Pictures">
    <perch:template path="content/_blocks/image.html" />
  </perch:block>
</perch:blocks>
Drew McLellan

Drew McLellan 2638 points
Perch Support

So you're talking about the "Sort By" field in the collection options?

Yeah.

I'm trying to find a balance between posting different style of posts and keep the ability to style them differently. (article, image, quote, etc.)

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok. Let me know if you have any issues with the real sorting functionality once you have the content on a page.