Forum
Modify a template output
Hello,
I'm a new user, so I'm playing around I trying to understand the Perch workflow to start developing our first site using Perch. I'm doing little things and reading the documentation, and right now I'm stuck with something.
I need to create an activity calendar, a simple list of dates and a descriptions. So each date has a description about that activity. I created a new template at templates/content/calendar.html with this content:
<p><perch:content id="activity" title="true" type="text" label="Activity" help="Activity description" /></p>
<p><perch:content id="date" type="date" label="Date" help="Activity date" /></p>
Next, I added a new region to my home page:
perch_content('Calendar');
Later I checked the box "Share across all pages" on my page region, because I need to replicate the calendar along all my pages. Finally I added a few items to the calendar. The items are listed on my home page as expected. So, I copied the region to another page and the items are listed as well.
So, here is my problem, and I don't know how to achieve this: I need to manipulate the dates on the list. So, if the date is 7 Aug 2007, I need to only extract the day and month, and print: 7, Aug.
I tried with perch_content_custom and the each option to manipulate the items, and works, but, I don't wanna replicate that piece of code on all my pages where I need to list my calendar, is not clean. So, I'm looking for a simplest solution as just typing perch_content('Calendar') and automatically manipulate the output of the template.
Cheers.
Ok, what I did finally is a mix between layouts and templates.
perch_content_custom
function with skip-template and here is where I finally manage the calendar output:So I'm using the Perch templates for managing the fields and the layout for presenting the calendar.
I don't know if this is the right way, I will wait a answer from experienced people to get some feedback.
AgustÃn, you can use the "format" tag attribute, since you want to manipulate a date, the date field docs has some examples
Thanks for the tip Andrés!
I was writing:
And I answer to my self according the docs we can re-use an ID of a field and use the content in different places on a template.
But my above example mixing templates and layouts, may be useful for other cases, I think, maybe if you need more flexibility than the templates gives us.
So the way to do this in the template would be:
The output can be i18n? I need the month in Spanish.
Sure. Set your locale to Spanish and then use
format="%m"
https://docs.grabaperch.com/docs/templates/attributes/type/date/