# Extension progress

**URL:** <https://www.ruby-forum.com/t/extension-progress/81603>\
**Category:** Radiant CMS\
**Created:** [January 10, 2007, 1:47pm UTC](https://www.ruby-forum.com/t/extension-progress/81603 "2007-01-10T13:47:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Todd\_McGrath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19b73/32.png) [@Todd\_McGrath](https://www.ruby-forum.com/u/Todd_McGrath)\
**Post date:** [January 10, 2007, 1:47pm UTC](https://www.ruby-forum.com/t/extension-progress/81603/1 "2007-01-10T13:47:34Z")

</div>

Hello again,

I’m making some progress on extensions and now I’m looking for a little  
push in  
the right direction.

I’m working on an extension for displaying data from database for the  
FAQ  
section of a site using tags (mental branch).

- Created a FaqExtension and include the tag:

- in lib/faq\_tag.rb:  
module FaqTag  
include Radiant::Taggable

end

- “faqhello” (\<r:faqhello/\>) works and “faq” tag is retrieving from db.  
(Obviously, I have an Answerbookpages class

I’m looking for some insight to take it further.

In my FAQ page, I’d like to use something like the following:

\<r:faq\>  
\<r:answername /\>  
\<r:summary /\>  
\</r:faq\>

where “answername” and “summary” are fields in the answerbookpages  
table.

Not sure where to begin…

In the StandardTags class, I see:

# 

# \<r:url /\>

# \<r:title /\>

# etc…

# 

((Page.column\_names.dup \<\< ‘url’) - [‘class\_name’, ‘created\_by’,  
‘updated\_by’]).each do |method|  
tag(method.to\_s) do |tag|  
tag.locals.page.send(method)  
end

Maybe the answer I’m looking for is something similar to this?

Any thoughts or suggestions are really appreciated

Thank you,  
Todd

---

<div class="post-metadata">

**Author:** ![Todd\_McGrath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19b73/32.png) [@Todd\_McGrath](https://www.ruby-forum.com/u/Todd_McGrath)\
**Post date:** [January 10, 2007, 4:16pm UTC](https://www.ruby-forum.com/t/extension-progress/81603/2 "2007-01-10T16:16:13Z")

</div>

Howdy Todd,

A combination of cloning the \<r:children:each\> tag (slightly lower in  
the same file) and the metamethod you pointed out should work just  
fine. So it would look more like:

\<r:faq:each\>  
\<r:answername /\>  
\<r:summary /\>  
\</r:faq:each\>

-jamie

---

<div class="post-metadata">

**Author:** ![Todd\_McGrath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19b73/32.png) [@Todd\_McGrath](https://www.ruby-forum.com/u/Todd_McGrath)\
**Post date:** [January 10, 2007, 10:57pm UTC](https://www.ruby-forum.com/t/extension-progress/81603/3 "2007-01-10T22:57:40Z")

</div>

On second glance… what do you need from a FAQ that can’t be  
accomplished with page children and a plethora of page parts?

-jamie

---

<div class="post-metadata">

**Author:** ![Todd\_McGrath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19b73/32.png) [@Todd\_McGrath](https://www.ruby-forum.com/u/Todd_McGrath)\
**Post date:** [January 10, 2007, 11:20pm UTC](https://www.ruby-forum.com/t/extension-progress/81603/4 "2007-01-10T23:20:46Z")

</div>

It’s the same thing I thought! But, on further review, the site has an  
existing  
table that is periodically updated from their CRM system (automated,  
batch  
style).

Jamie, thank you, I really appreciate the suggestion from earlier today.  
Haven’t had a chance to further work on it more today, but will report  
back to  
the list when progress is made. I assume other people want to be able  
to pull  
in existing database content in one way or another!? Hope that’s not a  
stretch and it helps other people out with there extension attempts.

Thanks again,  
Todd

Quoting Jamie W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Todd\_McGrath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19b73/32.png) [@Todd\_McGrath](https://www.ruby-forum.com/u/Todd_McGrath)\
**Post date:** [January 11, 2007, 5:37am UTC](https://www.ruby-forum.com/t/extension-progress/81603/5 "2007-01-11T05:37:34Z")

</div>

Todd: I’d make a few tweaks so you don’t have problems:

(Answerbookpage.content\_columns.dup).each do |column|  
tag “faq:#{column.name}” do |tag|  
tag.locals.answer.send(column.name).to\_s if tag.locals.answer  
end  
end

[snip]

tag “faq:each” do |tag|  
result = “”  
Answerbookpage.find(:all).each do |item|  
tag.locals.answer = item  
result \<\< tag.expand  
end  
result  
end

Let me explain why I suggest these.

1. Unless you want to display things like foreign keys, you probably  
don’t want ALL of the columns from your Answerbookpage model – just the  
ones that have actual useful content.
2. Scoping the tag under “faq” will prevent tags like \<r:answername /\>  
from working under any invalid context.
3. In both “faq:each” and the dynamically created tags, it’s best to  
define your own local rather than overwriting page. tags.locals.page  
should always refer to the currently rendering page (including  
contextual ones). I’m assuming you just grabbed some code from  
“children:each”. Besides “tag.locals.answer” says better what you’re  
passing around.
4. I added “.to\_s if tag.locals.answer” at the end of your line for a  
little safety. First, sometimes objects that you could get from a model  
could return some ugly inspect string instead of a real representation,  
and also, if somehow your tag gets out of context or gets ‘nil’ in  
tag.locals.answer, you won’t output anything ugly.
5. Everything you are outputting is a string , so ‘result’ in “faq:each”  
should be a string.

Hope this helps!

Cheers,  
Sean C.

---

<div class="post-metadata">

**Author:** ![Todd\_McGrath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19b73/32.png) [@Todd\_McGrath](https://www.ruby-forum.com/u/Todd_McGrath)\
**Post date:** [January 11, 2007, 5:16am UTC](https://www.ruby-forum.com/t/extension-progress/81603/6 "2007-01-11T05:16:33Z")

</div>

Well, that is exactly what I needed. Thanks again, Jamie!

I can’t say if the following code is the best, most efficient way, but  
here it  
is for posterity sake-

module FaqTag  
include Radiant::Taggable

class TagError \< StandardError; end

# \<r:answername /\>

# \<r:summary /\>

# etc…

# 

(Answerbookpage.column\_names.dup).each do |method|  
tag(method.to\_s) do |tag|  
tag.locals.page.send(method)  
end  
end

tag “faq” do |tag|  
tag.expand  
end

tag “faq:each” do |tag|  
result = []  
Answerbookpage.find(:all).each do |item|  
tag.locals.child = item  
tag.locals.page = item  
result \<\< tag.expand  
end  
result  
end

end

Quoting Jamie W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Todd\_McGrath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19b73/32.png) [@Todd\_McGrath](https://www.ruby-forum.com/u/Todd_McGrath)\
**Post date:** [January 11, 2007, 12:32pm UTC](https://www.ruby-forum.com/t/extension-progress/81603/7 "2007-01-11T12:32:10Z")

</div>

Got it nad it makes sense. Thank you!

Quoting Sean C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
