# New Date Tag

**URL:** <https://www.ruby-forum.com/t/new-date-tag/91495>\
**Category:** Radiant CMS\
**Created:** [April 9, 2007, 8:23pm UTC](https://www.ruby-forum.com/t/new-date-tag/91495 "2007-04-09T20:23:29Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![poopsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@poopsmith](https://www.ruby-forum.com/u/poopsmith)\
**Post date:** [April 9, 2007, 8:23pm UTC](https://www.ruby-forum.com/t/new-date-tag/91495/1 "2007-04-09T20:23:29Z")

</div>

Hi All,

I’m trying to code the new date tag we talked about earlier, but as  
I’m new to ruby, I’m posting the code for you to have a look.

desc %{  
Renders the actual date or the date the page was published, created or  
updated  
(in the event that it has not been published yet, the date that it  
was created).  
The format attribute uses the same formating codes used by the Ruby  
@strftime@  
function. By default it’s set to @%A, %B %d, %Y@.

_Usage:_

```

```

}  
tag ‘date’ do |tag|  
page = tag.locals.page  
format = (tag.attr[‘format’] || ‘%A, %B %d, %Y’)

if tag.attr[‘which’]  
if (tag.attr[‘which’] == ‘now’)  
date = Date::Time.now  
else  
which = tag.attr[‘which’] # are this two lines correct?  
date = page.which # i don’t know if it’s the way to do it  
end  
else  
date = page.published\_at || page.created\_at  
end

date.strftime(format)  
end

date\_type would be [created\_at | published\_at | updated\_at | now]

I need some help

Thanks,  
Gabriel

---

<div class="post-metadata">

**Author:** ![poopsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@poopsmith](https://www.ruby-forum.com/u/poopsmith)\
**Post date:** [April 9, 2007, 8:36pm UTC](https://www.ruby-forum.com/t/new-date-tag/91495/2 "2007-04-09T20:36:30Z")

</div>

How about this:

tag ‘date’ do |tag|  
page = tag.locals.page  
format = (tag.attr[‘format’] || ‘%A, %B %d, %Y’)  
which = tag.attr[‘which’]  
if which  
if (which == ‘now’)  
date = Date::Time.now  
elsif [‘published\_at’, ‘created\_at’, ‘updated\_at’].include? which  
date = page[which]  
else  
raise TagError, “Invalid value for ‘which’ attribute.”  
end  
else  
date = page.published\_at || page.created\_at  
end

date.strftime(format)  
end

Notice that I made sure it’s a valid attribute, otherwise raising an  
error.

If none of the core team has problems with this, I’ll write some tests  
and patch it into mental.

Sean

---

<div class="post-metadata">

**Author:** ![poopsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@poopsmith](https://www.ruby-forum.com/u/poopsmith)\
**Post date:** [April 9, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/new-date-tag/91495/3 "2007-04-09T22:20:45Z")

</div>

Sean C. wrote:

> and patch it into mental.  
> I like this, but am not sure that “which” is the right name for this  
> attribute.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![poopsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@poopsmith](https://www.ruby-forum.com/u/poopsmith)\
**Post date:** [April 9, 2007, 10:25pm UTC](https://www.ruby-forum.com/t/new-date-tag/91495/4 "2007-04-09T22:25:46Z")

</div>

select? I’m up for suggestions.

Sean

---

<div class="post-metadata">

**Author:** ![poopsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@poopsmith](https://www.ruby-forum.com/u/poopsmith)\
**Post date:** [April 9, 2007, 10:34pm UTC](https://www.ruby-forum.com/t/new-date-tag/91495/5 "2007-04-09T22:34:46Z")

</div>

Hello creators and other users of Radiant, I am fairly new to Radiant  
CMS and love it quite a bit. I have a question about navigation. I  
would like to be able to paginate my posts (ie. display Prev 1 2 3 4 5  
Next | Show All) and can’t seem to figure that out. I couldn’t find  
anything on the mailing list archive about it. Is this something that  
is possible? I would assume so considering I can limit the amount of  
Children a Parent will display.  
Thanks guys.

Derek

Derek Kinsman  
The Idea Company

New Media Designer

[http://www.ideacompany.ca/](http://www.ideacompany.ca/)  
[http://nincompoopery.ambitiouslemon.com/](http://nincompoopery.ambitiouslemon.com/)  
[http://boring.ambitiouslemon.com/](http://boring.ambitiouslemon.com/)  
1.416.371.5652

---

<div class="post-metadata">

**Author:** ![poopsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@poopsmith](https://www.ruby-forum.com/u/poopsmith)\
**Post date:** [April 9, 2007, 11:19pm UTC](https://www.ruby-forum.com/t/new-date-tag/91495/6 "2007-04-09T23:19:55Z")

</div>

Yes. I think Rails uses it, so it’s kind-of reserved.

Chris

---

<div class="post-metadata">

**Author:** ![poopsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@poopsmith](https://www.ruby-forum.com/u/poopsmith)\
**Post date:** [April 10, 2007, 12:15am UTC](https://www.ruby-forum.com/t/new-date-tag/91495/7 "2007-04-10T00:15:02Z")

</div>

No name collision, just not good practice. Although “type” can invoke  
the class of the current object, it doesn’t necessarily have to. Still,  
I would shy away from it. Here’s some more suggestions:

field  
column  
pick  
use

Sean

---

<div class="post-metadata">

**Author:** ![poopsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@poopsmith](https://www.ruby-forum.com/u/poopsmith)\
**Post date:** [April 10, 2007, 2:38am UTC](https://www.ruby-forum.com/t/new-date-tag/91495/8 "2007-04-10T02:38:13Z")

</div>

Sean C. wrote:

> No name collision, just not good practice. Although “type” can invoke  
> the class of the current object, it doesn’t necessarily have to. Still,  
> I would shy away from it. Here’s some more suggestions:
> 
> field  
> column  
> pick  
> use

How about “for”?

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![poopsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@poopsmith](https://www.ruby-forum.com/u/poopsmith)\
**Post date:** [April 10, 2007, 2:43am UTC](https://www.ruby-forum.com/t/new-date-tag/91495/9 "2007-04-10T02:43:14Z")

</div>

derek | idea company wrote:

> Hello creators and other users of Radiant, I am fairly new to Radiant  
> CMS and love it quite a bit. I have a question about navigation. I  
> would like to be able to paginate my posts (ie. display Prev 1 2 3 4 5  
> Next | Show All) and can’t seem to figure that out. I couldn’t find  
> anything on the mailing list archive about it. Is this something that  
> is possible? I would assume so considering I can limit the amount of  
> Children a Parent will display.

It could be done using an extension, but you can’t do this out of the  
box with Radiant.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![poopsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@poopsmith](https://www.ruby-forum.com/u/poopsmith)\
**Post date:** [April 10, 2007, 5:26am UTC](https://www.ruby-forum.com/t/new-date-tag/91495/10 "2007-04-10T05:26:24Z")

</div>

date\_type

\<r:date date\_type=“updated\_at” format="%B %d, %Y" /\>  
or  
\<r:date date\_type=“now” /\>

---

<div class="post-metadata">

**Author:** ![poopsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@poopsmith](https://www.ruby-forum.com/u/poopsmith)\
**Post date:** [April 9, 2007, 10:55pm UTC](https://www.ruby-forum.com/t/new-date-tag/91495/11 "2007-04-09T22:55:48Z")

</div>

Is ‘type’ already used for something else?

Walter

---

<div class="post-metadata">

**Author:** ![poopsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@poopsmith](https://www.ruby-forum.com/u/poopsmith)\
**Post date:** [April 10, 2007, 3:45pm UTC](https://www.ruby-forum.com/t/new-date-tag/91495/12 "2007-04-10T15:45:04Z")

</div>

On Apr 9, 2007, at 11:25 PM, Adam S. wrote:

> date\_type
> 
> \<r:date date\_type=“updated\_at” format="%B %d, %Y" /\>

That seems horribly redundant and repetitious. How about the more  
DRY \<r:date type=“updated\_at” /\>

~~ B

---

<div class="post-metadata">

**Author:** ![poopsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@poopsmith](https://www.ruby-forum.com/u/poopsmith)\
**Post date:** [April 10, 2007, 4:11pm UTC](https://www.ruby-forum.com/t/new-date-tag/91495/13 "2007-04-10T16:11:16Z")

</div>

2007/4/10, John W. Long [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> How about “for”?  
> How about “when” ?

\<r:date when=“updated\_at” /\>

\<r:date when=“now” /\>

---

<div class="post-metadata">

**Author:** ![poopsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@poopsmith](https://www.ruby-forum.com/u/poopsmith)\
**Post date:** [April 10, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/new-date-tag/91495/14 "2007-04-10T16:30:19Z")

</div>

Pierre-Charles D. wrote:

> How about “when” ?
> 
> \<r:date when=“updated\_at” /\>
> 
> \<r:date when=“now” /\>

“when” works for me.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![poopsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@poopsmith](https://www.ruby-forum.com/u/poopsmith)\
**Post date:** [April 10, 2007, 5:04pm UTC](https://www.ruby-forum.com/t/new-date-tag/91495/15 "2007-04-10T17:04:26Z")

</div>

[http://dev.radiantcms.org/radiant/changeset/366](http://dev.radiantcms.org/radiant/changeset/366)
