# Where to put helper methods for tags?

**URL:** <https://www.ruby-forum.com/t/where-to-put-helper-methods-for-tags/83692>\
**Category:** Radiant CMS\
**Created:** [January 28, 2007, 10:23pm UTC](https://www.ruby-forum.com/t/where-to-put-helper-methods-for-tags/83692 "2007-01-28T22:23:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaleb\_Walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/779978/32.png) [@Kaleb\_Walton](https://www.ruby-forum.com/u/Kaleb_Walton)\
**Post date:** [January 28, 2007, 10:23pm UTC](https://www.ruby-forum.com/t/where-to-put-helper-methods-for-tags/83692/1 "2007-01-28T22:23:01Z")

</div>

Where is an appropriate place to put helper methods for tags to  
support the DRY principle?

---

<div class="post-metadata">

**Author:** ![Kaleb\_Walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/779978/32.png) [@Kaleb\_Walton](https://www.ruby-forum.com/u/Kaleb_Walton)\
**Post date:** [January 29, 2007, 12:33am UTC](https://www.ruby-forum.com/t/where-to-put-helper-methods-for-tags/83692/2 "2007-01-29T00:33:20Z")

</div>

Tags are instance\_eval’d on the page, so depending on how your page  
hierachy either put them as a method on a superclass or put them in a  
module which is included in each of the pages.

---

<div class="post-metadata">

**Author:** ![Kaleb\_Walton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/779978/32.png) [@Kaleb\_Walton](https://www.ruby-forum.com/u/Kaleb_Walton)\
**Post date:** [January 29, 2007, 1:29am UTC](https://www.ruby-forum.com/t/where-to-put-helper-methods-for-tags/83692/3 "2007-01-29T01:29:27Z")

</div>

Thanks for that explanation!

I ended up creating a MyTags module that included tag definitions as  
well as helper methods. For those who may have the same question I did  
something like this:

In extensions/my\_tags/lib/my\_tags.rb:

module MyTags  
include Radiant::Taggable

def helper\_hello  
“hello”  
end

tag ‘hello’ do |tag|  
helper\_hello  
end  
end

In extensions/my\_tags/my\_tags\_extension.rb:

class MyTagsExtension \< Radiant::Extension  
version “1.0”  
description “Adds my tags to the global tag library”  
url “http://my\_tags.com”

def activate  
Page.send :include, MyTags  
end  
end

As you can see my helper method ‘helper\_hello’ is available from within  
my tags.

The above technique used to include tags in the global scope was  
suggested a few months back in this mailing list and I found it works  
out quite nicely.

Regards,  
Kaleb
