Forum

Thread tagged as: Question, Runway, Events

Custom fields in events: how to output categories and current month

Using Events (in Runway). Have created some custom fields including categories. Tried a few different ways to output the selected categories but can't make it work. This is the code in my listing html file:

<perch:before></perch:before>
    <div style="padding-left: 12px;"><perch:events id="eventDateTime" format="H:i" />&nbsp;
    <a href="<perch:events id="eventURL" />"><perch:events id="eventTitle" /></a> 
    <br />Event Desc: <perch:events id="eventDescHTML" />
    <br />Setting: <perch:events id="setting" /> <!-- custom field displays as expected -->

    <br />Service category: <perch:category id="Service" />
    <br />Choir category: <perch:category id="Choir" />

    <br />Month: <perch:events id="current_month" />
    </div>
<perch:after></perch:after>

And current_month returns nothing. What syntax should I use for this? John

John Liston

John Liston 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You're missing the <perch:categories> tag pair.

I've added the tag pair (two instances) but still nothing. I'm expecting/hoping to display one or more (or none) categories selected via the template when the event was created or edited.

<perch:before></perch:before>
    <div style="padding-left: 12px;"><perch:events id="eventDateTime" format="H:i" />&nbsp;
    <a href="<perch:events id="eventURL" />"><perch:events id="eventTitle" /></a> 
    <br />Event Desc: <perch:events id="eventDescHTML" />
    <br />Setting: <perch:events id="setting" /> <!-- custom field displays as expected -->

    <perch:categories id="service" set="service">    
        <br />Service category: <perch:category id="service" />
    </perch:categories>

    <perch:categories id="choir" set="choir">    
        <br />Choir category: <perch:category id="choir" />
    </perch:categories>    

    <br />Month: <perch:events id="current_month" />
    </div>

<perch:after></perch:after>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Which template is this in?

I have a global layout item which includes this perch_events_custom code

                perch_events_custom(array(
                    'filter'=>'eventDateTime',
                    'match'=>'between',
                    'value' => date('Y-m-d 00:00:00'). ', ' . date('Y-m-d 23:59:59'),
                    'sort'=>'eventDateTime',
                    'sort-order'=>'desc',
                    'template'=>'listing/banner-listing.html'
                ));

The template code in the reply above is listing/banner-listing.html

The template events>event.html looks like this

<div class="vevent">
    <h2 class="summary"><perch:events id="eventTitle" /></h2>

<perch:categories id="event" label="Event Category" set="event" required="true" display-as="list" help="Select one or more event categories." order="4" />
<perch:categories id="service" label="Service category" set="service" required="true" display-as="list" help="Select one or more services." order="5" />
<perch:categories id="choir" label="Choir(s)" set="choir" required="false" display-as="list" help="Optional: Select one or more choirs." order="6" />

    <p class="dtstart"><span class="value-title" title="<perch:events id="eventDateTime" format="c" /></span></p>

    <div>
        <perch:events id="setting" label="Setting" type="text" required="false" encode="false" />
        <perch:events id="psalm" label="Psalm(s)"  type="text" required="false" encode="false" />
        <perch:events id="anthem" label="Anthem(s)"  type="text" required="false" encode="false" />
        <perch:events id="voluntary" label="Voluntary"  type="text" required="false" encode="false" />

    </div>

    <perch:categories id="president" label="President" set="President" required="false" display-as="list" help="Select President" />


    <div class="description"><perch:events id="eventDescHTML" type="textarea" html="true" editor="ckeditor" encode="false" size="xs" /></div>

    <p class="category"><perch:events id="category_names" encode="false" /></p>


</div>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Does the editing of the categories work as expected?

I have five sets of categories all populated through the categories app. I've opted to display them as a dropdown list. I can select one or more of them and the selections are shown in the field on the edit event details page. The selected categories are show greyed out in the dropdown lists.

Debug shows:


Debug Message SELECT u.*, r.* FROM perch2_users u, perch2_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='xxxx' LIMIT 1 UPDATE perch2_users SET userHash='xxxx' WHERE userID='1' SELECT p.privKey FROM perch2_user_privileges p SELECT * FROM (SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=1 OR userID=0 ORDER BY userID DESC) AS settings GROUP BY settingID SELECT collectionID, collectionKey FROM perch2_collections WHERE collectionInAppMenu=1 ORDER BY collectionOrder ASC SELECT * FROM perch2_events_categories ORDER BY categoryTitle ASC SELECT * FROM perch2_events WHERE eventID = 15 SELECT categoryID FROM perch2_events_to_categories WHERE eventID = 15 SELECT c.* FROM perch2_events_categories c, perch2_events_to_categories e2c WHERE c.categoryID=e2c.categoryID AND e2c.eventID='15' Using template: /templates/events/event.html SELECT * FROM perch2_categories WHERE catID=15 LIMIT 1 SELECT * FROM perch2_categories WHERE catID=10 LIMIT 1 SELECT * FROM perch2_categories WHERE catID=1 LIMIT 1 SELECT * FROM perch2_categories WHERE catID=25 LIMIT 1 UPDATE perch2_events SET eventTitle='Morning Prayer', eventDescRaw='<p>Description here: Service and Concert, Morning Prayer, Visiting and this is the setting</p>', eventDateTime='2015-08-25 09:00:00', eventDynamicFields='{\"event\":[\"15\",\"10\"],\"service\":[\"1\"],\"choir\":[\"25\"],\"setting\":\"this is the setting\",\"psalm\":null,\"anthem\":null,\"voluntary\":null,\"president\":null}', eventDescHTML='<p>Description here: Service and Concert, Morning Prayer, Visiting and this is the setting</p>', eventSlug='2015-08-25-morning-prayer' WHERE eventID='15' No ids to log. DELETE FROM perch2_events_to_categories WHERE eventID='15' INSERT INTO perch2_events_to_categories(eventID,categoryID) VALUES('15','1') SELECT c.* FROM perch2_events_categories c, perch2_events_to_categories e2c WHERE c.categoryID=e2c.categoryID AND e2c.eventID='15' SELECT c.categoryID, COUNT(p2c.eventID) AS qty FROM perch2_events_categories c, perch2_events_to_categories p2c, perch2_events p WHERE p2c.categoryID=c.categoryID AND p2c.eventID=p.eventID AND p.eventDateTime>='2015-08-25 15:24:00' GROUP BY c.categoryID ORDER BY c.categoryTitle ASC UPDATE perch2_events_categories SET categoryFutureEventCount='1' WHERE categoryID='1' LIMIT 1 SELECT c.categoryID, COUNT(p2c.eventID) AS qty FROM perch2_events_categories c, perch2_events_to_categories p2c, perch2_events p WHERE p2c.categoryID=c.categoryID AND p2c.eventID=p.eventID GROUP BY c.categoryID ORDER BY c.categoryTitle ASC UPDATE perch2_events_categories SET categoryEventCount='12' WHERE categoryID='1' LIMIT 1 SELECT * FROM perch2_categories c, perch2_category_sets s WHERE c.setID=s.setID AND s.setSlug='event' ORDER BY catTreePosition ASC SELECT * FROM perch2_categories c, perch2_category_sets s WHERE c.setID=s.setID AND s.setSlug='service' ORDER BY catTreePosition ASC SELECT * FROM perch2_categories c, perch2_category_sets s WHERE c.setID=s.setID AND s.setSlug='choir' ORDER BY catTreePosition ASC SELECT * FROM perch2_categories c, perch2_category_sets s WHERE c.setID=s.setID AND s.setSlug='President' ORDER BY catTreePosition ASC Queries: 31 Memory: 4.4076
Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, great. What does your output template look like?

This is the page (still in development).

<?php
    // output the top of the page incl css
    perch_layout('global/top', [
        'page_title' => perch_page_title(true),
    ]);

    {echo '<div id="layout-container" class="max-1180 sidebar-none">';}

    // sticky top menu
    perch_layout('global/stickymenu');

    // top navigation
    perch_layout('global/nav');

    {echo '<div id="content">';}

    // top images
    perch_layout('global/topimages');

    // main navigation not being used yet
    perch_pages_navigation([
        'levels'   => 1,
        'template' => 'main_nav.html',
    ]);


    perch_content('main content');
    perch_content('body content');

    {echo '</div><!-- end content -->';}


    // closing footer
    perch_layout('global/footer');

perch_layout('global/topimages') is html and includes this php

~~~~ <?php

            perch_events_custom(array(
                'filter'=>'eventDateTime',
                'match'=>'between',
                'value' => date('Y-m-d 00:00:00'). ', ' . date('Y-m-d 23:59:59'),
                'sort'=>'eventDateTime',
                'sort-order'=>'desc',
                'template'=>'listing/banner-listing.html'
            ));

?>


And this is the template banner-listing.html

<perch:before></perch:before> <div style="padding-left: 12px;"><perch:events id="eventDateTime" format="H:i" />  <a href="<perch:events id="eventURL" />"><perch:events id="eventTitle" /></a> <br />Event Desc: <perch:events id="eventDescHTML" /> <br />Setting: <perch:events id="setting" /> <!-- custom field displays as expected -->

<perch:categories id="service" set="service">    
    <br />Service category: <perch:category id="service" />
</perch:categories>

<perch:categories id="choir" set="choir">    
    <br />Choir category: <perch:category id="choir" />
</perch:categories>    

<br />Month: <perch:events id="current_month" />
</div>

<perch:after></perch:after> ~~~

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think this:

<perch:categories id="service" set="service">    
    <br />Service category: <perch:category id="service" />
</perch:categories>

should be:

<perch:categories id="service" set="service">    
    <br />Service category: <perch:category id="catTitle" />
</perch:categories>

That's it. Thank you Drew. Should I raise a separate thread about current_month; I can't get it to display. John

Drew McLellan

Drew McLellan 2638 points
Perch Support

Where are you setting current_month ?

I'm not; and that will be why! I assumed current_month would be available since I was displaying an event. How do I do this?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What are you expecting it to be - the month of the event or the current month based on the current time?

Should have been clear: month of the event.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Should be:

<perch:events id="eventDateTime" type="date" format="F" />

See here for all the formatting options: https://php.net/manual/en/function.date.php

Brilliant; thank you.