# Throw default text when yield doesn't render anything?

**URL:** <https://www.ruby-forum.com/t/throw-default-text-when-yield-doesnt-render-anything/82247>\
**Category:** Rails\
**Created:** [January 18, 2007, 3:25pm UTC](https://www.ruby-forum.com/t/throw-default-text-when-yield-doesnt-render-anything/82247 "2007-01-18T15:25:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kayros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kayros](https://www.ruby-forum.com/u/kayros)\
**Post date:** [January 18, 2007, 3:25pm UTC](https://www.ruby-forum.com/t/throw-default-text-when-yield-doesnt-render-anything/82247/1 "2007-01-18T15:25:05Z")

</div>

hello,

I’m wondering if there’s a way to do something like : \<%=  
yield :catchphrase || “default text” %\> ?

## Thanks.

Nicolas C.

> **[Bounga’s Home](https://www.bounga.org/)**
>
> Thoughts about Ruby, Rails, Hanami, Elixir, Phoenix, Javascript and Unix.

> **[Nicolas Cavigneaux Resume](https://www.cavigneaux.net/)**
>
> Nicolas Cavigneaux Resume

---

<div class="post-metadata">

**Author:** ![kayros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kayros](https://www.ruby-forum.com/u/kayros)\
**Post date:** [January 18, 2007, 3:28pm UTC](https://www.ruby-forum.com/t/throw-default-text-when-yield-doesnt-render-anything/82247/2 "2007-01-18T15:28:05Z")

</div>

Le 18 janv. 07 à 15:23, Nicolas C. a écrit :

> hello,
> 
> I’m wondering if there’s a way to do something like : \<%=  
> yield :catchphrase || “default text” %\> ?

## \<%= yield(:catchphrase) || “default text” %\> works, sorry.

Nicolas C.

> **[Bounga’s Home](https://www.bounga.org/)**
>
> Thoughts about Ruby, Rails, Hanami, Elixir, Phoenix, Javascript and Unix.

> **[Nicolas Cavigneaux Resume](https://www.cavigneaux.net/)**
>
> Nicolas Cavigneaux Resume

---

<div class="post-metadata">

**Author:** ![kayros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kayros](https://www.ruby-forum.com/u/kayros)\
**Post date:** [January 18, 2007, 4:42pm UTC](https://www.ruby-forum.com/t/throw-default-text-when-yield-doesnt-render-anything/82247/3 "2007-01-18T16:42:14Z")

</div>

About time someone deprecate \<%= @content\_for\_foo %\> too. You should go  
\<%= yield(:foo) %\> instead, and do \<% if yield(:foo) %\> (or perhaps  
unless yield(:foo).empty? Not sure) if you need to check if it has  
contents. Yield ftw!
