show upcoming events

0 views
Skip to first unread message

Matt Spendlove

unread,
Jun 18, 2010, 8:44:21 AM6/18/10
to Radiant CMS
Hi all

I have a News page of archive page type. Users can tag the pages into
"news", "events", "offers" etc.
I'd like to be able to show upcoming events in a sidebar.

I can search for all items tagged with "events" and display them, but
how do I show only events where <r: date> >= TODAY ?

I didn't really want to go down the route of using a dedicated
calendar extension [1] as it's overkill for the requirements. I can't
see to be able to do any kind of conditional fiter on the date?

Your thoughts appreciated.

Matt


[1] http://github.com/davec/radiant-events-calendar-extension

Jim Gay

unread,
Jun 18, 2010, 9:21:03 AM6/18/10
to radia...@googlegroups.com

There's no notion of "upcoming" with the archive pages.
To do this, you'll need to create an new tag (in a custom extension).

Here's some quick code that should get you along:

tag 'upcoming' do |tag|
tag.locals.upcoming = Page.all(:conditions => ['whatever_date > ?',Time.now]
tag.expand
end
tag 'upcoming:each' do |tag|
result = []
tag.locals.upcoming.each do |page|
tag.locals.page = page
result << tag.expand
end
result
end


--
Jim Gay
Saturn Flyer LLC
http://www.saturnflyer.com
571-403-0338

Matt Spendlove

unread,
Jun 18, 2010, 9:30:02 AM6/18/10
to Radiant CMS
Thanks Jim.

I realise that it's a unusual usage as News items are normally either
current or past but the thinking was they'd post a News item as at
"today" referring to an upcoming event. Perhaps we'll have to rethink
this..

Matt

Josh French

unread,
Jun 18, 2010, 9:36:50 AM6/18/10
to radia...@googlegroups.com
If you're on edge, you might also consider the PageParts extension. It
can be used to add a dedicated datetime field to a page (instead of
storing dates as text, or repurposing published_at.) It also provides
some new tags like if_earlier/if_later for working with datetime fields.

j

Steven Southard

unread,
Jun 18, 2010, 9:42:23 AM6/18/10
to radia...@googlegroups.com
With the backdoor extension you can do something like this.


<r:ruby>
@date_today = <r:date for='now' format='%Y%j' />
""
</r:ruby>

<r:ruby>
@date_article = <r:date format='%Y%j' />
""
</r:ruby>

<r:if cond=" @date_today == @date_article ">Show Upcoming events</r:if>

Brian Loomis

unread,
Jun 18, 2010, 10:09:20 AM6/18/10
to radia...@googlegroups.com
What does this mean? being on edge?

On Jun 18, 2010, at 7:36 AM, Josh French wrote:

> If you're on edge

Brian Loomis

Matt Spendlove

unread,
Jun 18, 2010, 10:13:57 AM6/18/10
to radia...@googlegroups.com
Brian - Edge is the latest version of code in the repository i.e. not
a guaranteed stable release. See http://radiantcms.org/download/

----------------------------------------------
http://cenatus.org/
http://radialsolutions.co.uk/
----------------------------------------------

Brian Loomis

unread,
Jun 18, 2010, 1:07:35 PM6/18/10
to radia...@googlegroups.com
anyone?

Brian Loomis

Matt Spendlove

unread,
Jun 18, 2010, 1:11:52 PM6/18/10
to Radiant CMS
Brian - see my previous reply. Sometimes the threads get a bit a bit
out of order with Google Groups. Check here:
http://groups.google.com/group/radiantcms/browse_thread/thread/143ace2ec13506da

Josh French

unread,
Jun 18, 2010, 1:42:08 PM6/18/10
to radia...@googlegroups.com
We could have avoided this had I been more accurate. PageParts works
fine on the latest release candidate gem, and I believe the prerelease
gem before that as well.

Marshal Linfoot

unread,
Jun 19, 2010, 3:00:07 PM6/19/10
to radia...@googlegroups.com
Hi Brian.

In case you're thinking about using the page_parts extension, I have a simple example to show how that might work for you. Page_factory and page_parts are two excellent extensions, by the way -- highly recommend them. Page_parts comes with some built-in custom parts, in particular the datetime part is very useful.

In my site, I use page_parts to define the startdate and enddate of events. These are tabs that have a calendar date picker, really convenient when adding a new event, less error prone than typing the date. The content of the startdate and enddate parts can then be used anywhere in your site. Let's say from some other page you wanted to list upcoming events. The code would look something like this:

  <ul>
  <r:find url="/events">
     <r:children:each>
        <r:if_later part="startdate">
           <li><r:date for="startdate" format="%A, %B %d:" /> <r:title /></li>
        </r:if_later>
     </r:children:each>
  </r:find>
  </ul>

This assumes your events are ordered by start date. 

Hope this helps as a starting place for some ideas.
--
marshal

Matt Spendlove

unread,
Jun 21, 2010, 12:41:33 PM6/21/10
to radia...@googlegroups.com
Hi Marshall/Josh

Thanks for the info.
I've installed Page Factory and Page Parts and I agree, very useful
functionality.

Unfortunately I get an error when I try and output the date held in my
start_page part using the <r:date for="start_date" /> tag. I can
output the date just fine if I use <r:content part="start_date"/> ,
obviously the date is then unformatted:

StandardTags::TagError (Invalid value for 'for' attribute.):
vendor/radiant/app/models/standard_tags.rb:597:in `tag:date'
vendor/radiant/lib/radiant/taggable.rb:33:in `send'
vendor/radiant/lib/radiant/taggable.rb:33:in `render_tag'
vendor/radiant/app/models/page_context.rb:10:in `initialize'
vendor/radiant/vendor/radius/lib/radius/context.rb:62:in `call'
vendor/radiant/vendor/radius/lib/radius/context.rb:62:in `render_tag'
vendor/radiant/vendor/radius/lib/radius/context.rb:93:in `stack'
vendor/radiant/vendor/radius/lib/radius/context.rb:61:in `render_tag'
vendor/radiant/app/models/page_context.rb:18:in `render_tag'
vendor/radiant/vendor/radius/lib/radius/parser.rb:50:in `stack_up'
vendor/radiant/vendor/radius/lib/radius/parse_tag.rb:12:in `call'
vendor/radiant/vendor/radius/lib/radius/parse_tag.rb:12:in `to_s'
vendor/radiant/vendor/radius/lib/radius/parser.rb:54:in `stack_up'
vendor/radiant/vendor/radius/lib/radius/tag_binding.rb:33:in `call'
vendor/radiant/vendor/radius/lib/radius/tag_binding.rb:33:in `expand'
vendor/extensions/page_parts/lib/page_parts/page_part_tags.rb:65:in
`tag:if_later'

I installed Page Parts with script/extension install and I'm on 0.9RC2.
Any ideas out there? Josh?

Cheers

Matt


----------------------------------------------
http://cenatus.org/
http://radialsolutions.co.uk/
----------------------------------------------

Josh French

unread,
Jun 21, 2010, 1:13:32 PM6/21/10
to radia...@googlegroups.com
Looks like Radiant isn't finding the extended r:date definition. I'll
take a look and get back to you.

j

Matt Spendlove

unread,
Jun 21, 2010, 1:14:30 PM6/21/10
to radia...@googlegroups.com
Sure, thanks. Let me know if you need any info from my setup..

----------------------------------------------
http://cenatus.org/
http://radialsolutions.co.uk/
----------------------------------------------

Josh French

unread,
Jun 21, 2010, 4:09:20 PM6/21/10
to radia...@googlegroups.com
I've pushed a small change, can you update & make sure it's working
for you?

Related question for the list: anyone know how to reliably overwrite
an existing tag description so that the reference is updated?

Jim Gay

unread,
Jun 21, 2010, 4:25:22 PM6/21/10
to radia...@googlegroups.com
On Mon, Jun 21, 2010 at 4:09 PM, Josh French <jo...@digitalpulp.com> wrote:
> I've pushed a small change, can you update & make sure it's working for you?
>
> Related question for the list: anyone know how to reliably overwrite an
> existing tag description so that the reference is updated?

I haven't tried it, but a guess would be to override the
tag_descriptions on Page in the extension activate method.
http://github.com/radiant/radiant/blob/master/lib/radiant/taggable.rb#L46

--

Matt Spendlove

unread,
Jun 21, 2010, 5:48:57 PM6/21/10
to radia...@googlegroups.com
Hi Josh

Thanks very much for looking at this. Seems to have done the trick
though I did uncover another potential problem, I typo'd the name of
my page part in the "for" attribute initially and I got the stack
below. Fixing the typo meant the date displayed correctly but I'm
guessing you might wanna scope TagError in..

NameError (uninitialized constant PageParts::PagePartTags::TagError):
vendor/extensions/page_parts/lib/page_parts/page_part_tags.rb:152:in


`tag:date'
vendor/radiant/lib/radiant/taggable.rb:33:in `send'
vendor/radiant/lib/radiant/taggable.rb:33:in `render_tag'
vendor/radiant/app/models/page_context.rb:10:in `initialize'
vendor/radiant/vendor/radius/lib/radius/context.rb:62:in `call'
vendor/radiant/vendor/radius/lib/radius/context.rb:62:in `render_tag'
vendor/radiant/vendor/radius/lib/radius/context.rb:93:in `stack'
vendor/radiant/vendor/radius/lib/radius/context.rb:61:in `render_tag'
vendor/radiant/app/models/page_context.rb:18:in `render_tag'
vendor/radiant/vendor/radius/lib/radius/parser.rb:50:in `stack_up'
vendor/radiant/vendor/radius/lib/radius/parse_tag.rb:12:in `call'
vendor/radiant/vendor/radius/lib/radius/parse_tag.rb:12:in `to_s'
vendor/radiant/vendor/radius/lib/radius/parser.rb:54:in `stack_up'
vendor/radiant/vendor/radius/lib/radius/tag_binding.rb:33:in `call'
vendor/radiant/vendor/radius/lib/radius/tag_binding.rb:33:in `expand'
vendor/extensions/page_parts/lib/page_parts/page_part_tags.rb:65:in
`tag:if_later'

Cheers

Matt

Josh French

unread,
Jun 22, 2010, 9:41:41 AM6/22/10
to radia...@googlegroups.com
Good catch, thanks. A fix has been pushed.
Reply all
Reply to author
Forward
0 new messages