# If-then-else in tags or any best practice?

**URL:** <https://www.ruby-forum.com/t/if-then-else-in-tags-or-any-best-practice/83422>\
**Category:** Radiant CMS\
**Created:** [January 25, 2007, 9:54pm UTC](https://www.ruby-forum.com/t/if-then-else-in-tags-or-any-best-practice/83422 "2007-01-25T21:54:12Z")\
**Posts on this page:** 5\
**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 25, 2007, 9:54pm UTC](https://www.ruby-forum.com/t/if-then-else-in-tags-or-any-best-practice/83422/1 "2007-01-25T21:54:12Z")

</div>

In the default radius tags, is there a way to replicate if-then-else  
flow?

Something like:  
\<r:if\_content part=“testy”\>  
x  
\<r:else/\>  
y  
\</r:if\_content\>

or

\<r:choose\>  
\<r:when part=“testy”\>  
x  
\</r:when\>  
\<r:otherwise\>  
y  
\</r:otherwise\>  
\</r:choose\>

Or, is the idea to use an "r:unless\ __" with an r:if\__ tag:

```
<r:unless_content part="specs">
 <li class="X">x</li>
</r:unless_content>
<r:if_content part="specs">
 <li class="Y">y</li>
</r:if_content>

```

-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 25, 2007, 10:10pm UTC](https://www.ruby-forum.com/t/if-then-else-in-tags-or-any-best-practice/83422/2 "2007-01-25T22:10:15Z")

</div>

Right now, the last way you mentioned is the only way I know of.  
However,  
if you have some better tag designs (with patch preferably), they would  
be  
welcomed!

Sean

---

<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 25, 2007, 10:25pm UTC](https://www.ruby-forum.com/t/if-then-else-in-tags-or-any-best-practice/83422/3 "2007-01-25T22:25:18Z")

</div>

Thanks Sean. I really hope the tone of my original email was not  
negative or  
condescending. The unless/if works for me, just wondering if there was  
a  
better way to do it.

The day I’m able to confidently submit a patch will be a good day. I  
need to  
learn much more Ruby.

Quoting Sean C. [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 25, 2007, 10:27pm UTC](https://www.ruby-forum.com/t/if-then-else-in-tags-or-any-best-practice/83422/4 "2007-01-25T22:27:19Z")

</div>

Not at all. Neither did I mean mine to be confrontational. Just trying  
to  
encourage participation!

Sean

---

<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 26, 2007, 1:17am UTC](https://www.ruby-forum.com/t/if-then-else-in-tags-or-any-best-practice/83422/5 "2007-01-26T01:17:41Z")

</div>

Todd McGrath wrote:

> In the default radius tags, is there a way to replicate if-then-else flow?
> 
> Something like:  
> \<r:if\_content part=“testy”\>  
> x  
> \<r:else/\>  
> y  
> \</r:if\_content\>

It would be hard to get Radius to parse this.

> \<r:choose\>  
> \<r:when part=“testy”\>  
> x  
> \</r:when\>  
> \<r:otherwise\>  
> y  
> \</r:otherwise\>  
> \</r:choose\>

That’s an interesting idea. Though perhaps it should work more like  
Ruby:

\<r:case\>  
\<r:when part=“foo”\>  
x  
\</r:when\>  
\<r:when part=“bar”\>  
y  
\</r:when\>  
\<r:else\>  
z  
\</r:else\>  
\</r:case\>

The difficulty is that Radius doesn’t provide a way to make true  
conditional statements. That’s one of the nice aspects of it being a  
tagging library (it isolates you from the conditionals and forces you to  
put advanced logic in custom tags).

I suppose the when tag could just have a number of attributes that would  
allow you to make predefined comparisons:

url=“…”  
url\_starts\_with=“…”  
url\_ends\_with=“…”  
has\_part=“…”

But that seems rather convoluted.

Perhaps the case tag could specify an object (doing some sort of  
variable expansion) and the when tag could do comparisons:

\<r:case object=“${page.title}”\>  
\<r:when equals=“foo”\>  
x  
\</r:when\>  
\<r:when ends\_with=“bar”\>  
y  
\</r:when\>  
\<r:else\>  
z  
\</r:else\>  
\</r:case\>

But again, it all seems convoluted.

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