Forum

Thread tagged as: Question, Events

Event Module or custom_content for type="file"

I need to have 3 event sections over 2 pages (ie shared template) - list of future events on my home page and an events page with a section listing future events and section listing past events.

If I use the event module, I cant work out how to add attachments to my events (the doc attachment in the description file shows [cms:asset 109 title=”Spring Walk 2018”] rather than a link to my doc. https://www.cannizaropark.com/cannizaro-pages/events1.php (nb not formatted yet) I can add in an event type="file" into event.html - but its not showing in the admin panel when I add an event. I'm guessing this isnt the right way.

If I use a normal content template with multiple items (with content type ="file") this works fine for future events on both pages but I'm struggling to filter it using perch_custom_content (either on date, or on the "past" checkbox I have added to the template. I havent gone too far with this option, as I've read that you cant use shared templates with custom_content. If I can use shared templates with custom_content, and this is the right way, I will post my code in the hope that someone will spot what I have done wrong.

cow shed

cow shed 0 points

  • 3 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hi,

as I've read that you cant use shared templates with custom_content

Can you explain what you mean by "shared template" so we're on the same page?

You can use the same template with perch_content_custom():

perch_content_custom('Events', [
'template' => 'events_list.html',
]);

And on other pages:

perch_content_custom('Events', [
'template' => 'events_list.html',
'page' => '/events.php'
]);

but I'm struggling to filter it using perch_custom_content (either on date, or on the "past" checkbox I have added to the template.

If you have a date field, you can filter events based on that without having to mark past events manually.

Hi thanks for looking at this By shared template I mean a template where I click "share across all pages" in the Region Options. But now i re-read the post I was trying to fix this with, I cant see that it is a problem so that probably isnt it (https://docs.grabaperch.com/templates/passing-variables-into-templates/)

I think my problem is that I'm not using the custom_content properly. I'm used to perch_blog_custom where I dont need to pass anything in so I'm really not sure what I should be passing in here.

My template is :

<perch:content type="checkbox" id="pastevent" value="1" label="Event Over" suppress="true" />
<perch:events id="eventDateTime" format="%c" type="text" label="Event Date Full" required="true" title="true" />
<perch:if exists="pastevent">
<perch:else />
<p class="event-text">
<span class="event-date">
    <perch:content id="eventdate" type="text" label="Event Date" required="true" title="true" />
</span>  
<perch:content id="text" type="text" label="Event Details." markdown="true" editor="markitup"  />
     <a href=
    "<perch:content id="report" type="file" label="Optional : Event Document - eg flyer or Newsletter">" >

    <perch:content id="text2" type="text" label="Attachment Description"/> 

    </a>

</p>
</perch:if>

and the code I am using for my page is below (I've tried 3 different ways...!)

By date
            <?php 
                perch_content_custom('eventDateTime', array(
                    'filter'=>'eventDateTime',
                    'match'=>'gte',
                    'value'=>date('Y-m-d'),
                    'count'=>10,
                    'sort'=>'eventDateTime',
                    'sort-order'=>'desc',
                    'template'=>'cannizaro-events.html'
                ));
            ?>  

  By Past Event
      <?php 
                perch_content_custom('pastevent', array(
                    'match'=>'neq',
                    'value'=>'1',
                    'count'=>10,
                    'sort'=>'eventDateTime',
                    'sort-order'=>'desc',
                    'template'=>'cannizaro-events.html'
                ));
            ?>  
  By Past Event using Events
      <?php 
                perch_content_custom('Events', array(
                    'match'=>'neq',
                    'value'=>'1',
                    'count'=>10,
                    'sort'=>'eventDateTime',
                    'sort-order'=>'desc',
                    'template'=>'cannizaro-events.html'
                ));
            ?>  

I've tried it 3 ways - none gives a result, even though I have past and future date events set up and ones with the Past Event clicked. I've also tried passing in 'Events' as you suggest, and that gives me nothing either.

The template works fine if I call it as perch_content (shows in orange section under Forthcoming events https://www.cannizaropark.com/cannizaro-pages/events.php).

Thanks so much

Drew McLellan

Drew McLellan 2638 points
Perch Support

By shared template I mean a template where I click "share across all pages" in the Region Options.

If you're using perch_content_custom() you don't need the region to be shared. Instead you can use the page option to target a region from a different page.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

It's like Drew stated; you don't need to use a shared region for this.

In your code you are using different region keys:

perch_content_custom('eventDateTime');
perch_content_custom('pastevent');
perch_content_custom('Events');

You want to query the same region. A region has only one key. So these all should be the same.

I think it would be helpful to you to go through these docs and tutorials:

In your template, you're also using both perch: content and perch:events... If you are working in the events app, the template needs to refer to that app space. All the tags should be perch:events tags.

Thank you for all your suggestions.

I am going to use the event app as that is working well for me for Event title, description and date. https://www.cannizaropark.com/cannizaro-pages/events1.php

However I would like to allow Perch users to add an attachment to the description (for event flyers).

The event description field has the option to attach a file, but as in my original post this adds [cms:asset 109 title=”Spring Walk 2018”] rather than a link to the attachment.

Therefore I would like to add a perch event id of type file to be entered with the rest of the event.

I have edited event.html to add the report field but when I add a new event in Perch Admin, the new fields do not show.

Presumably event.html is not the right template for entering event details? Can anyone help me let a user add a pdf file to the event when they enter the event details?

My Event.html code is below (nb I have commented out the image as I dont need this, but it still shows when I am in the Perch Admin adding a new event).

<div class="vevent">

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

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

    <div class="description"><perch:events id="eventDescHTML" type="textarea" markdown="true" editor="simplemde" size="m" encode="false" /></div>


<a href="<perch:event id="file" type="file" label="File" order="2" />">

<perch:content type="reportDesc" id="desc" label="Title" order="1" required="true" title="true" /></a>   


<!--    <p class="category"><perch:events id="category_names" encode="false" /></p>
-->    
<!--    <perch:if exists="image">
        <img src="<perch:events id="image" type="image" label="Image" width="640" crop="true" />" alt="<perch:events id="eventTitle" />" />
    </perch:if>
--></div>
<a href="<perch:event id="file" type="file" label="File" order="2" />">  

<perch:content type="reportDesc" id="desc" label="Title" order="1" required="true" title="true" /></a>  

So if that's your template, your perch tags all need to be perch:events tags. So 2 errors above. Fix those and the items will appear in your admin. Should be:

<a href="<perch:events id="file" type="file" label="File" order="2" />">  

<perch:events type="reportDesc" id="desc" label="Title" order="1" required="true" /></a>  

And I don't think the title tag will work here as the events app uses the date and the event title. You can only set title in the content app.

And, yes, in templates, perch will read in field definitions even if they are within comment tags. If you want to comment them out so perch ignores them too, see this page: https://docs.grabaperch.com/templates/comments/

Thanks so much. Its all working now