# Lose global tags when a page uses a Behavior?

**URL:** <https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804>\
**Category:** Radiant CMS\
**Created:** [September 6, 2006, 10:45pm UTC](https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804 "2006-09-06T22:45:04Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 6, 2006, 10:45pm UTC](https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804/1 "2006-09-06T22:45:04Z")

</div>

I’m seeing some interesting behavior (so to speak) with global tags  
(please correct me if that’s the wrong term). If I have the following  
in app/behaviors/hello\_behavior.rb:

class Behavior::Base  
define\_tags do  
tag “hello” do |tag|  
“Hello World!”  
end  
end  
end

I would expect to be able to write \<r:hello/\> in any page to render  
the text “Hello World!”.

This seems to work fine on pages that do not have a behavior  
specified (i.e., the “Behavior” drop down is left at “”).  
However, if I select the Archive behavior, instead of “Hello World!”  
I get:

```
<div><strong>undefined tag `hello'</strong></div>

```

Any thoughts? If it’s a bug I’m happy to look into the cause. I just  
thought I’d ask on the list before I started spelunking.

- Sean

PS I’m running on trunk revision 114

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 6, 2006, 11:11pm UTC](https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804/2 "2006-09-06T23:11:06Z")

</div>

Sean,

You may have found a bug that happened to me too! I used \<r:parent\>  
tags  
(from somebody’s plugin) on some of my pages (that had the Commentable  
behavior), and now they are broken, but somehow the code\_behavior plugin  
isn’t. Maybe there’s a subtle difference in the code that I’m missing?

Sean C.  
[seancribbs.com](http://seancribbs.com)

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 9, 2006, 11:52pm UTC](https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804/3 "2006-09-09T23:52:20Z")

</div>

The same thing happened to me, too, as described here:

[http://www.ruby-forum.com/topic/80740](http://www.ruby-forum.com/topic/80740)

It always happens if I assign a behavior to the page that has a  
“define\_tags” section, while behaviors wthout specific tags leave my  
global tags untouched.

So I guess what happens is that the behavior class overwrites the tags  
defined in the Behavior::Base extension instead of adding their tags to  
it.

Could that be the case?

Wolfgang

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 11, 2006, 2:23am UTC](https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804/4 "2006-09-11T02:23:50Z")

</div>

I think that if you move your global tags definition into the  
PageContext.rbyou wont have that problem, if these are realy global  
tags I think this is  
where you want them.  
Or create a plugin that extends PageContext.  
Dror

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 10, 2006, 1:51pm UTC](https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804/5 "2006-09-10T13:51:47Z")

</div>

Just wanted to tell you that I found an albeit ugly solution to my  
problem:

[http://www.ruby-forum.com/topic/80740](http://www.ruby-forum.com/topic/80740)

Maybe it’s of help for you, too.

Cheers,  
Wolfgang

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 11, 2006, 6:54pm UTC](https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804/6 "2006-09-11T18:54:43Z")

</div>

Wolfgang,

Instead of changing PageContext, change Behavior::Base, like so

Behavior::Base.define\_tags do  
tag “mytag” do |tag|  
…  
end  
…  
end

Just make sure that it loads before anything else, i.e. make the plugin  
folder start with 01\_ or something.

Cheers,

Sean C.  
[seancribbs.com](http://seancribbs.com)

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 11, 2006, 6:48pm UTC](https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804/7 "2006-09-11T18:48:38Z")

</div>

Thanks for the suggestion!

I tried reopening PageContext and adding my define\_tags in a plugin, but  
Rails didn’t seem to like that and refused to start. I required  
page\_context.rb to load the model class during plugin initialization and  
extend it properly, but that approach didn’t work.

Any idea what I’m doing wrong?

Wolfgang

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 11, 2006, 7:11pm UTC](https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804/8 "2006-09-11T19:11:10Z")

</div>

Sean,

thanks, but that’s exactly what I’m doing right now - I just thought  
extending PageContext might be the more elegant solution than prefixing  
my plugin directories… Anyway - I’ll go with what works.

Cheers,  
Wolfgang

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 11, 2006, 8:38pm UTC](https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804/9 "2006-09-11T20:38:54Z")

</div>

Sean C. wrote:

> Yeah, I don’t know that it will get you anything, though. At issue is the  
> order in which the tags are loaded/defined, i.e. if a behavior is defined  
> before your global tags, those global tags won’t work on pages that have  
> the  
> behavior.

But if you can define them on PageContext they will be available on  
every page.

Wolfgang, are you overriding PageContext#intialize and then calling  
#define\_tag ?

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

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 11, 2006, 8:52pm UTC](https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804/10 "2006-09-11T20:52:55Z")

</div>

Hi Wolfgang and John,

It might be worth if it works in production and not in development, I  
had a  
similar problem with the PageContext and with a tagging plugin I did. My  
solution was to put the code in PageContext.rb - test it in development  
and  
then move it to the plugin and test again in production.  
I know this is a ugly solution, but I fifn’t find any other,

Dror

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 11, 2006, 7:20pm UTC](https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804/11 "2006-09-11T19:20:45Z")

</div>

Wolfgang,

Yeah, I don’t know that it will get you anything, though. At issue is  
the  
order in which the tags are loaded/defined, i.e. if a behavior is  
defined  
before your global tags, those global tags won’t work on pages that have  
the  
behavior.

Sean

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 12, 2006, 2:16pm UTC](https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804/12 "2006-09-12T14:16:50Z")

</div>

Wolfgang Wopperer wrote:

> If I understand you correctly, I have to override the initialize method  
> and call define\_tags from there?

Something like this would probably work:

require ‘page\_context’

class PageContext \< Radius::Context  
def initialize(page)  
super

```
   define_tag "hello" do
     "hello world!"
   end

   . . .

 end

```

end

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

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 12, 2006, 9:11am UTC](https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804/13 "2006-09-12T09:11:06Z")

</div>

John,

at the moment, I only have something like this:

class PageContext  
define\_tags do  
…  
end  
end

If I understand you correctly, I have to override the initialize method  
and call define\_tags from there?

Thanks for further explanations!

Wolfgang

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [September 12, 2006, 5:36pm UTC](https://www.ruby-forum.com/t/lose-global-tags-when-a-page-uses-a-behavior/67804/14 "2006-09-12T17:36:29Z")

</div>

Thanks for the information, John.

Unfortunately, that didn’t work, too. But since I can’t test it locally  
at the moment and hence provide no details, I’ll go with the other  
solution for the moment and post again when I can tell you more.

Wolfgang
