CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • Truncating Upcomming Events Block
Pages: [1]

Author Topic: Truncating Upcomming Events Block  (Read 2042 times)

junglecoder

  • Guest
Truncating Upcomming Events Block
November 18, 2009, 09:27:17 pm
Greetings,

The upcoming events block that I have placed in the side column on a Drupal site is so long that it goes well beyond page content for most pages. I found two ways to truncate this block, which I will share, but I am looking for a long term solution that will survive employee turn-over or civicrm upgrades.

1) Editing .tpl file method:
templates/CRM/Block/Event.tpl
My additions in bold:

<div id="crm-event-block">
{foreach from=$eventBlock item=ev name=uevents}
   {if $smarty.foreach.uevents.item lt 10}
    <p>
    <a href="{$ev.url}">{$ev.title}</a><br />
    {$ev.start_date|truncate:10:""|crmDate}<br />
    {assign var=evSummary value=$ev.summary|truncate:80:""}
    <em>{$evSummary}{if $ev.summary|count_characters:true GT 80}  (<a href="{$ev.url}">{ts}more{/ts}...</a>){/if}</em>
    </p>
   {/if}
{/foreach}
</div>

2) Truncating SQL query method:
CRM/Event/BAO/Event.php
Edit made at line 666  :-\

 ...WHERE civicrm_event.is_active = 1
      AND civicrm_event.is_public = 1
      AND civicrm_event.start_date >= {$condition}";
    
        if(isset( $eventId )) {
            $query .= " AND civicrm_event.id =$eventId ";
      }
        $query .=" ORDER BY   civicrm_event.start_date ASC limit 10";


Both of these methods worked for me, and the second uses less processing, but how can I give the site content creators the ability to edit the number of events listed. There doesn't seem to be any administration menu / controls to do this.

Thanks in advance :)

junglecoder

  • Guest
Re: Truncating Upcomming Events Block
March 23, 2010, 12:59:45 am
After upgrading to the latest civiCRM, the smarty method did not work for me. But, I was able to truncate the SQL query by adding the limit 10. The new line number in CRM/Event/BAO/Event.php is now 754:

$query .=" ORDER BY   civicrm_event.start_date ASC limit 10";

mhoefer

  • I’m new here
  • *
  • Posts: 9
  • Karma: 0
Re: Truncating Upcomming Events Block
April 23, 2011, 07:46:18 am
Thanks Junglecoder... this solved an issue I had been beating my head against the wall for months. Not sure why the upcomming events does not use the Views Interface (or have some sort of configuration setting on the Civi Admin Side of things)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Truncating Upcomming Events Block
April 23, 2011, 04:38:21 pm

1. Cant use views since that block is used for joomla also. However there is a sample "event listing" block included in the views distribution

2. yes, would be nice to have some sort of configuratio setting on the Civi Admin side of things. Can you contribute code to do so (and if u r not a developer, please consider hiring someone to do so). We need folks to step up and "scratch their OWN itch" in addition to wondering why something like this is not present by default

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

friendswoodtech

  • I’m new here
  • *
  • Posts: 28
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7
  • MySQL version: 5.1.56
  • PHP version: 5.3.6
Re: Truncating Upcomming Events Block
September 30, 2011, 06:32:00 am
I actually got the smarty method to work like this.

Line 31
        {foreach from=$eventBlock item=ev name=foo}
         {if $smarty.foreach.foo.iteration < 6}  *** input the limiting number here

Add
             {else break}
             {/if}
after </p> - which would now be at line 39

I didn't want to make a change to the query because I also wanted to be able to have a listing via HTML for all events and changing the query affected this as well.  Thanks for pointing me in the right direction!
« Last Edit: September 30, 2011, 11:34:35 am by friendswoodtech »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • Truncating Upcomming Events Block

This forum was archived on 2017-11-26.