# Erb syntax - unknown syntax

**URL:** <https://rubytalk.org/t/erb-syntax-unknown-syntax/66585>\
**Category:** ruby-talk\
**Created:** [30 October 2012 04:59 UTC](https://rubytalk.org/t/erb-syntax-unknown-syntax/66585 "2012-10-30T04:59:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [30 October 2012 04:59 UTC](https://rubytalk.org/t/erb-syntax-unknown-syntax/66585/1 "2012-10-30T04:59:44Z")

</div>

Hi, I am a very beginner on Ruby and related stuff, Could you please  
tell me  
what a tag like this "\<%!" means in the following code. Also, I would  
really appreciate if you can give me some ref to erb templates.

\<%! if filmstrip\_image\_path.blank? %\>

Also what does this '?' do in the above code

Thanks,  
Georgy

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![stomar](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@stomar](https://rubytalk.org/u/stomar)\
**Post date:** [30 October 2012 09:12 UTC](https://rubytalk.org/t/erb-syntax-unknown-syntax/66585/2 "2012-10-30T09:12:49Z")

</div>

> Hi, I am a very beginner on Ruby and related stuff, Could you please  
> tell me  
> what a tag like this "\<%!" means in the following code. Also, I would  
> really appreciate if you can give me some ref to erb templates.

The official documentation can be found here:

> **[Class: ERB (Ruby 1.9.3)](https://ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html)**
>
> Class : ERB - Ruby 1.9.3

or use `ri ERB' in the command line.

> \<%! if filmstrip\_image\_path.blank? %\>
> 
> Also what does this '?' do in the above code

It's just part of the method name `blank?'.  
By convention, methods with a name ending with  
a question mark return a boolean value, false or true.

> **···**
>
> Am 30.10.2012 05:59, schrieb Georgy Daniel:
> 
> --  
> \<[https://github.com/stomar/&gt](https://github.com/stomar/&gt);

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [30 October 2012 09:33 UTC](https://rubytalk.org/t/erb-syntax-unknown-syntax/66585/3 "2012-10-30T09:33:38Z")

</div>

okay what about the '!' in \<%! if filmstrip\_image\_path.blank? %\>

unknown wrote in post #1081937:

> **···**
>
> > Am 30.10.2012 05:59, schrieb Georgy Daniel:
> > 
> > > Hi, I am a very beginner on Ruby and related stuff, Could you please  
> > > tell me  
> > > what a tag like this "\<%!" means in the following code. Also, I would  
> > > really appreciate if you can give me some ref to erb templates.
> > 
> > The official documentation can be found here:  
> > [Class: ERB (Ruby 1.9.3)](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html)
> > 
> > or use `ri ERB' in the command line.
> > 
> > > \<%! if filmstrip\_image\_path.blank? %\>
> > > 
> > > Also what does this '?' do in the above code
> > 
> > It's just part of the method name `blank?'.  
> > By convention, methods with a name ending with  
> > a question mark return a boolean value, false or true.
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![stomar](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@stomar](https://rubytalk.org/u/stomar)\
**Post date:** [30 October 2012 10:13 UTC](https://rubytalk.org/t/erb-syntax-unknown-syntax/66585/4 "2012-10-30T10:13:49Z")

</div>

Sorry, no clue. It doesn't seem to be a part of erb.

I guess it should be parsed as a boolean `not'.  
But to see whether that makes sense here, you would have  
to provide more of the surrounding code, especially the  
rest of the if statement.

> **···**
>
> Am 30.10.2012 10:33, schrieb Georgy Daniel:
> 
> > okay what about the '!' in \<%! if filmstrip\_image\_path.blank? %\>
> 
> --  
> \<[https://github.com/stomar/&gt](https://github.com/stomar/&gt);

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [30 October 2012 12:10 UTC](https://rubytalk.org/t/erb-syntax-unknown-syntax/66585/5 "2012-10-30T12:10:55Z")

</div>

I don't think it is associated with the if condition, here there is  
another instance of the '!'

\<%!  
&nbsp;&nbsp;&nbsp;require 'cgi'  
&nbsp;&nbsp;require 'json'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.....................  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.....................  
%\>

Also here is the if condition block

\<%! if filmstrip\_image\_path.blank? %\>  
&nbsp;&nbsp;&nbsp;\<div id="main-page"\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<img src="resources/image.jpg" alt="My Image"\>\</img\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<img id="main-page-text" src="resources/image.png"\>\</img\>  
&nbsp;&nbsp;&nbsp;\</div\>  
\<%! end %\>

unknown wrote in post #1081950:

> **···**
>
> > Am 30.10.2012 10:33, schrieb Georgy Daniel:
> > 
> > > okay what about the '!' in \<%! if filmstrip\_image\_path.blank? %\>
> > 
> > Sorry, no clue. It doesn't seem to be a part of erb.
> > 
> > I guess it should be parsed as a boolean `not'.  
> > But to see whether that makes sense here, you would have  
> > to provide more of the surrounding code, especially the  
> > rest of the if statement.
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![stomar](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@stomar](https://rubytalk.org/u/stomar)\
**Post date:** [30 October 2012 17:25 UTC](https://rubytalk.org/t/erb-syntax-unknown-syntax/66585/6 "2012-10-30T17:25:53Z")

</div>

And this code works? Are you really using the standard erb?  
For me (ruby 1.9.3p194), the following template gives a syntax error

\<%! if true %\>  
&nbsp;&nbsp;&nbsp;true  
\<%! end %\>

Because this is interpreted as

&nbsp;&nbsp;&nbsp;! if true  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...  
&nbsp;&nbsp;&nbsp;! end

where the first '!' is possible but completely useless here,  
and the second '!' is syntactically wrong.

The fact that \<%! has no special meaning but is treated  
like \<% and the boolean `!' can be seen here:

&nbsp;&nbsp;&nbsp;require 'erb'  
&nbsp;&nbsp;&nbsp;template = \<\<EOF  
&nbsp;&nbsp;&nbsp;\<%! false && (text = 'true!!!') %\>  
&nbsp;&nbsp;&nbsp;\<%= text %\>  
&nbsp;&nbsp;&nbsp;EOF  
&nbsp;&nbsp;&nbsp;puts ERB.new(template).result

outputs `true!!!', because the ruby code is taken to be

&nbsp;&nbsp;&nbsp;!false && (text = 'true!!!')

and the assignment of `true!!!' to the variable takes place.  
The same with \<%! true && ... %\> gives no output, as expected.

> **···**
>
> Am 30.10.2012 13:10, schrieb Georgy Daniel:
> 
> > I don't think it is associated with the if condition, here there is  
> > another instance of the '!'
> > 
> > \<%!  
> > &nbsp;&nbsp;&nbsp;&nbsp;require 'cgi'  
> > &nbsp;&nbsp;&nbsp;require 'json'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.....................  
> > %\>
> > 
> > Also here is the if condition block
> > 
> > \<%! if filmstrip\_image\_path.blank? %\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;\<div id="main-page"\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<img src="resources/image.jpg" alt="My Image"\>\</img\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<img id="main-page-text" src="resources/image.png"\>\</img\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;\</div\>  
> > \<%! end %\>
> 
> --  
> \<[https://github.com/stomar/&gt](https://github.com/stomar/&gt);

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [2 November 2012 03:10 UTC](https://rubytalk.org/t/erb-syntax-unknown-syntax/66585/7 "2012-11-02T03:10:38Z")

</div>

Thanks you, I really appreciate your help on this.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
