I’ve taken the calendar.php blueprint provided and added the code below in my home.php blueprint
calendar:
label: Calendar
type: structure
entry: >
<strong>{{summary}}</strong><br>
{{description}}<br>
Beginning: {{_begin_date}} {{_begin_time}}<br>
End: {{_end_date}} {{_end_time}}
fields:
summary:
label: Summary
type: text
description:
label: Description
type: textarea
size: small
_begin_date:
label: Beginning date
type: date
format: MM/DD/YYYY
_begin_time:
label: Beginning time
type: time
interval: 15
_end_date:
label: Ending date
type: date
format: MM/DD/YYYY
_end_time:
label: Ending time
type: time
interval: 15
now in my home.php template i want to be able to access these fields and include them in the theme forest template i’ve purchased. I’ve included the following code in my custom home.php file.
<?php $calendar = calendar($page->calendar()->yaml()); ?>
It’s my understanding that this needs to be here. Below is the code i’d like to add the calendar fields to. This code is directly below the code above in my home.php template
<li class="event-list-item">
<span class="event-date">
<span class="date">18</span>
<span class="month">Jan</span>
<span class="year">2016</span>
</span>
<div class="event-list-cont">
<span class="meta-data">Monday, 07:00 PM</span>
<h4 class="post-title"><a href="#">Fundraising for meals</a></h4>
<p>Lorem ipsum dolor sit amet, consectet adipiscing elit Cras sed nunc</p>
</div>
</li>
How do i call the calendar fields from my home.php blueprint? The entries are appearing in the home.txt content file. I should be able to call them.
This line
<?php $calendar = calendar($page->calendar()->yaml()); ?>
needs to be changed to:
<?php $calendar = $page->calendar()->yaml(); ?>
Then you can call individual subfields like this, e.g. the description:
<?php echo $calendar['description'] ?>
Thank you for your reply. I get the error : ‘Undefined index: description in /Applications/MAMP/htdocs/ogrin.dev/html/orgin/kirby/site/templates/home.php’
This is how my blueprint is arranged. calendar field at the bottom. Is it formatted wrong?
<?php if(!defined('KIRBY')) exit ?>
title: Home
pages: false
fields:
title:
label: Title
type: text
headerlogo:
label: Header Logo
type: select
options: images
line:
type: line
firstsliderimage:
label: First Slider Image
type: select
default: unsplashmanfield1280x800.jpeg
options: images
required: true
a-info:
label: "Note:"
type: info
text: >
Please select an image 1280x800 pixels.
sliderHeading1:
label: Slider Heading (Photo 1)
type: text
a-line:
type: line
featuredLinkSpan1:
label: Featured Link Text 1
type: text
width: 1/3
featuredLinkAction1:
label: Action Text 1
type: text
width: 1/3
featuredLink1URL:
label: Featured Link 1 URL
type: url
width: 1/3
b-line:
type: line
fulltitle:
label: Full Title/Heading
type: text
companyBio:
label: Company Bio
type: textarea
size: large
c-line:
type: line
info:
type: info
text: >
Featured Project Section
firstfeaturedprojectimage:
label: First Image
type: select
default: orgainicgrains.jpg
options: images
required: true
width: 1/3
secondfeaturedprojectimage:
label: Second Image
type: select
default: orgainicpotatoes.jpeg
options: images
required: true
width: 1/3
thirdfeaturedprojectimage:
label: Third Image
type: select
default: buckwheat.jpg
options: images
required: true
width: 1/3
featuredproject1:
label: First Description
type: textarea
size: small
width: 1/3
featuredproject2:
label: Second Description
type: textarea
size: small
width: 1/3
featuredproject3:
label: Third Description
type: textarea
size: small
width: 1/3
project1link:
label: First Project Link
type: url
width: 1/3
project2link:
label: Second Project Link
type: url
width: 1/3
project3link:
label: Third Project Link
type: url
width: 1/3
d-line:
type: line
b-info:
type: info
text: >
Featured News Story Section
newsStory1Title:
label: Story Title
type: text
newsStory1:
label: Story Exerpt
type: textarea
size: large
storyLink1URL:
label: Story Link
type: url
firstStoryImage:
label: News Story Image
type: select
default: news1photo600x400.jpg
options: images
required: true
f-line:
type: line
newsStory2Title:
label: Story Title
type: text
newsStory2:
label: Story Exerpt
type: textarea
size: large
storyLink2URL:
label: Story Link
type: url
secondStoryImage:
label: News Story Image
type: select
default: news2photo600x400.jpg
options: images
required: true
e-line:
type: line
newsStory3Title:
label: Story Title
type: text
newsStory3:
label: Story Exerpt
type: textarea
size: large
storyLink3URL:
label: Story Link
type: url
thirdStoryImage:
label: News Story Image
type: select
default: news3photo600x400.jpg
options: images
required: true
g-line:
type: line
calendar:
label: Upcoming Events
type: structure
entry: >
<strong>{{summary}}</strong><br>
{{description}}<br>
Beginning: {{_begin_date}} {{_begin_time}}<br>
End: {{_end_date}} {{_end_time}}
fields:
summary:
label: Summary
type: text
description:
label: Description
type: textarea
size: small
_begin_date:
label: Beginning date
type: date
format: MM/DD/YYYY
_begin_time:
label: Beginning time
type: time
interval: 15
_end_date:
label: Ending date
type: date
format: MM/DD/YYYY
_end_time:
label: Ending time
type: time
interval: 15
h-line:
type: line
footerlogo:
label: Footer Logo
type: select
options: images
footerimage:
label: Footer Image
type: select
default: unsplashwomanfield1280x400.jpg
options: images
required: true
Sorry, I got up too early this morning, it seems. You need to loop through the array, of course:
<?php
$calendar = $page->calendar()->yaml();
foreach($calendar as $calendarEntry) {
echo $calendarEntry['description'];
}
?>
Edit: Please help to improve code readability by enclosing blocks of code withing three backticks at the beginning and the end of a block on a separate line. I have corrected your code above. To see how it works, click on the pencil icon of your post. Thank you.
I added
<?php $calendar = $page->calendar()->yaml();
foreach($calendar as $calendarEntry) {
echo $calendarEntry['description'];
It returned nothing. Below is how the entries appear in my home.txt file
----
Calendar:
-
summary: New entry
description: Hello World!
_begin_date: 2016-03-01
_begin_time: ""
_end_date: ""
_end_time: ""
-
summary: One more
description: ...hello again
_begin_date: 2016-03-04
_begin_time: ""
_end_date: ""
_end_time: ""
----
the entries were recorded in the .txt. Just not echoed.
Never mind. Problem solved! The area I was test echoing out the fields wasn’t showing the content BUT it was still echoing it out. Thank you for your help!
Great that you found a solution.
Concerning syntax highlighting: You used three apostrophes instead of three backticks. I corrected it above again. No big deal, but please do it like that in the future.
I have a follow up question. I now need to call the calendar() fields that are in my home.txt in my event.php. I’m assuming that the $page (below) now needs to be manually set to home. I’ve tried a few different approaches without any luck.
foreach($calendar as $calendarEntry) {
echo $calendarEntry['description'];
}
?>```
also...where those the right ticks to enclose code in?
Thanks again,
Dave
You can fetch the home page from another template like this:
<?php $calendar = page('home')->calendar()->yaml(); ?>
Just for your information: In case you ever want to fetch any descendant page, you need to pass the uri, e.g. page('projects/project-a')
.