# \[ANN\] BackDoor 0.4.0: Attribute expansion

**URL:** <https://www.ruby-forum.com/t/ann-backdoor-0-4-0-attribute-expansion/122886>\
**Category:** Radiant CMS\
**Created:** [December 12, 2007, 7:18pm UTC](https://www.ruby-forum.com/t/ann-backdoor-0-4-0-attribute-expansion/122886 "2007-12-12T19:18:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aitor\_Garay-Romero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@Aitor\_Garay-Romero](https://www.ruby-forum.com/u/Aitor_Garay-Romero)\
**Post date:** [December 12, 2007, 7:18pm UTC](https://www.ruby-forum.com/t/ann-backdoor-0-4-0-attribute-expansion/122886/1 "2007-12-12T19:18:49Z")

</div>

Hi there!,

New feature: Attribute expansion. From the README:

---- 8\< ----  
== Attribute expansion

Back Door allows evaluating tag’s attributes as Ruby code. If a tag’s  
attribute starts with the “#” symbol, the rest of the attribute is  
evaluated, and the attribute’s value is replaced with the evaluated  
value.  
This works for both standard Radiant (Radius) tags and Back Door’s own  
tags.

As an example, consider a side-bar where we want to show first and  
second  
level pages. But for the “news” page, we want to limit the number of  
children to 3 and add an extra link to see all news. Without Back Door  
this  
could be implemented as:

\<r:children:each\>

## \<r:link\> \<r:title /\> \</r:link\>
  
\<r:if\_url matches="/news/"\>  
\<r:children:each limit=“3” order=“desc” by=“published\_at”\>  

### \<r:link\> \<r:title /\> \</r:link\>
  
\</r:children:each\>  

### \<r:link\> More news… \</r:link\>
  
\</r:if\_url\>  
\<r:unless\_url matches="/news/"\>  
\<r:children:each order=“desc” by=“published\_at”\>  

### \<r:link\> \<r:title /\> \</r:link\>
  
\</r:children:each\>  
\</r:unless\_url\>  
\</r:children:each\>

Clearly there is too much duplication. With Back Door this can be  
rewritten  
as:

\<r:children:each\>

## \<r:link\> \<r:title /\> \</r:link\>
  
\<r:ruby\> @news = tag.locals.page.url =~ /news/; “” \</r:ruby\>  
\<r:children:each limit="#@news ? ‘3’:‘1000’" order=“desc”  
by=“published\_at”\>  

### \<r:link\> \<r:title /\> \</r:link\>
  
\</r:children:each\>  
\<r:if cond="@news"\>  

### \<r:link\> More news… \</r:link\>
  
\</r:if\>  
\</r:children:each\>

Note how the “limit” attribute of the \<r:children:each\> tag uses the “#”  
symbol to make it dynamic.  
---- 8\< ----

```
 /AITOR
```

---

<div class="post-metadata">

**Author:** ![Aitor\_Garay-Romero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@Aitor\_Garay-Romero](https://www.ruby-forum.com/u/Aitor_Garay-Romero)\
**Post date:** [December 12, 2007, 7:48pm UTC](https://www.ruby-forum.com/t/ann-backdoor-0-4-0-attribute-expansion/122886/2 "2007-12-12T19:48:30Z")

</div>

Just after releasing it, i noticed a small detail. I have corrected  
this  
in the new 0.4.1 version. From the CHANGELOG:

=== 0.4.1

- Automatically convert to string the result of evaluating tag  
attributes,  
so the user does not have to take care of this

---

<div class="post-metadata">

**Author:** ![Aitor\_Garay-Romero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@Aitor\_Garay-Romero](https://www.ruby-forum.com/u/Aitor_Garay-Romero)\
**Post date:** [December 12, 2007, 9:54pm UTC](https://www.ruby-forum.com/t/ann-backdoor-0-4-0-attribute-expansion/122886/3 "2007-12-12T21:54:29Z")

</div>

What a problematic release…

```
 There is a problem when running Radiant in "development" 

```

environment.  
You get this error:

```
 "Error calling Dispatcher.dispatch #<NameError: method `attr' not

```

defined in Radius::TagBinding\>"

```
 Seems that BackDoor gets loaded before Radius (?). This does not

```

happen in “production” and “test” environments… I will take a look to  
this in the following days, until then please use release 0.3.0 if you  
use  
“development” environment. Sorry for the inconvenience.

```
 /AITOR
```

---

<div class="post-metadata">

**Author:** ![Aitor\_Garay-Romero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@Aitor\_Garay-Romero](https://www.ruby-forum.com/u/Aitor_Garay-Romero)\
**Post date:** [December 14, 2007, 12:21pm UTC](https://www.ruby-forum.com/t/ann-backdoor-0-4-0-attribute-expansion/122886/4 "2007-12-14T12:21:34Z")

</div>

OK, new 0.4.2 release solves the problem in development environment.

Enjoy,

/AITOR
