Forum

Thread tagged as: Question

if different="date"

How can I achieve that the date is only visible if the year has changed? Actually every article from this year shows 2015 using the following code. I think the problem is that the last before putting a new one already has the title 2015. It should then disappear from the second last. Here's my code:


<perch:if different="date" format="Y"> <p class="quote"><perch:content id="date" type="date" label="Jahr" format="Y" required="true" /></p> </perch:if>

Many thanks!

Martin Stettler

Martin Stettler 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

That code should work. Is that the entire template?

Here is the entire template. The date is used a second time what shouldn't be a problem, right?


<div class="row row-centered"> <div class="col-sm-6 col-sm-offset-3"> <perch:if different="date" format="Y"> <p class="quote"><perch:content id="date" type="date" label="Jahr" format="Y" required="true" /></p> </perch:if> </div> </div><!-- /.row --> <div class="row voffset"> <div class="col-sm-5 col-sm-offset-1"> <perch:blocks> <perch:block type="image" label="Bild"> <perch:if exists="image"> <perch:if exists="link"> <a href="<perch:content id="link" type="text" label="Download-Link (fakultativ)" help="/perch/resources/dateiname.pdf" />"> </perch:if> <div class="image"> <img src="<perch:content type="image" label="Bild" id="image" width="720" help="Masse mind: 720 x 480 (3:2)" />" alt="<perch:content type="text" id="alt" label="Bildlegende (unsichtbar)" help="SEO relevant!" title="true" />" /> </div> <perch:if exists="link"> </a> </perch:if> </perch:if> </perch:block> <perch:block type="movie" label="Film"> <perch:if exists="youtube"> <div class="movie-item"> <div class="video-container"> <perch:content id="youtube" label="youtube iframe" type="textarea" html="true" help="iframe-Code hier einfügen (Masse mind. 1280px breit)"size="xs"/> </div> <div class="video-lightbox"> <a href="https://www.youtube.com/watch?v=<perch:content id="youtube-link" type="url" label="youtube URL" help="Nur ID eintragen (ohne https://youtu.be/)" />"><h5 class="movie" style="background-image: url(../../../graphics/movie-button.svg), url(<perch:content id="bgimage-youtube" type="image" label="youtube Vorschaubild" help="Masse: 480 x 320 (3:2)" />);"></h5></a> </div> </div> </perch:if> </perch:block> </perch:blocks> </div> <div class="col-sm-5"> <p class="quote"><perch:content id="date" type="date" label="Datum" format="%d. %B %Y" required="true"/></p> <h2 class="quote"><perch:content id="heading" type="text" label="Titel"/></h2> <perch:content id="text" type="textarea" label="Text" textile="true" editor="markitup" html="true" size="m"/> </div> </div><!-- /.row -->
Drew McLellan

Drew McLellan 2638 points
Perch Support

No, that shouldn't be a problem. Discounting the blocks, how many items do you have in the region?

  1. col: date, image & link (1. block), movie & link (2. block)
  2. col: date, heading, text
Drew McLellan

Drew McLellan 2638 points
Perch Support

So you have two items in the region, both from the same year?

Exactly, once only the year, once the whole date. The year should be visible only on top of all articles of the same year.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you getting it for both or for neither?

Every article with a date from the same year has on top the row with the year.

Drew McLellan

Drew McLellan 2638 points
Perch Support

By every, you mean both? Because you have two items.

Sorry to be pedantic, but something about your language is making me think I don't have a clear picture of what is happening on this page.

No problem, I try to be clear! The hole region can be used as many times as necessary, let's say each is a (news)article. One article has e.g. an image, a date and text. Let's say there are 3 articles with a date from 2015. So on top of them should be 2015 as a title. Shall I send you the URL?

Drew McLellan

Drew McLellan 2638 points
Perch Support

The URL would be helpful!

A region can only be used multiple times by adding it to the page multiple times:

perch_content('Articles');
perch_content('Articles');

I suspect you're talking about a multiple item region. In that case the date is compared with the last item in the region.

Right it is a multiple region. Here is the URL: https://www.schertenlaibundjegerlehner.ch/news-archiv.php

Drew McLellan

Drew McLellan 2638 points
Perch Support

So your region currently has 4 items?

<perch:content ... />

are totally 7 in the template.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

In the admin. How many items have you added to this Region? So how many times have you completed the form to add an item?

Sorry! There are 4 items (2x 2015, 1x 2014, 1x 2008)

Drew McLellan

Drew McLellan 2638 points
Perch Support

I can't see any reason why that shouldn't work.