The g> tag helper makes it easy to write hyperlinks .

<%= link_to index => begin%> Home <%end%>
<%= link_to index => {foo =>'bar'} => (class =>'links') => begin%>
  Home
<%end%>
<%= link_to'/ path/to/file' => begin%> File <%end%>
<%= link_to'http://mojolicio.us' => begin%> Mojolicious <%end%>
<%= link_to url_for->query(foo => $foo) => begin%> Retry <%end%>

It will be expanded to the following HTML. The first argument is the root name or path. You can also pass a Mojo::URL object. The last argument is a block, which allows you to specify the text of the hyperlink.

<a href="/path/to/index">Home</a>
<a class="links" href="/path/to/index/bar">Home</a>
<a href="/path/to/file">File</a>
<a href="http://mojolicio.us">Mojolicious</a>
<a href="/current/path?foo=something">Retry</a>

Describe image tags

The image tag helper makes it easy to write image tags .

<%= image'/images/foo.png' %>
<%= image'/images/foo.png', alt =>'Foo' %>

It will be expanded as follows. The first argument is the URL to the image. This URL is expanded by the url_for method. The remaining arguments are used as attributes.

<img src="/images/foo.png" />
<img alt = "Foo" src="/images/foo.png" />

Style sheet (CSS)

The stylesheet tag helper makes it easy to write external links to stylesheets and stylesheets.

<%= stylesheet'/foo.css' %>
<%= stylesheet begin%>
  # body {color: 000}
<%end%>

When specifying a link to an external style sheet, describe the path in the first argument. If you want to describe the style sheet itself, specify the block (begin to end) as the first argument. It will be expanded to the following HTML.

<link href="/foo.css" media = "screen" rel = "stylesheet" type = "text/css" />
<style type = "text/css"><! [CDATA [
  # body {color: 000}
]]> </style>

JavaScript source code

The javascript tag helper makes it easy to write JavaScript source code.

%= javascript'/script.js';
%= javascript begin
  var a = 'b';
%end

The argument can be an external JavaScript path or block (begin to end). You can write the actual JavaScript source code inside the block.

<script src="/script.js" type = "text/javascript" />
<script type = "text/javascript"><! [CDATA [
  var a = 'b';
]]> </script>

Input tag

The input_tag tag helper makes it easy to write input tags .

<%= input_tag'first_name' %>
<%= input_tag first_name =>'Default name' %>
<%= input_tag'employed', type =>'checkbox' %>
<%= input_tag'country', type =>'radio', value =>'germany' %>

It will be expanded as follows. The first argument is the value of name and the remaining arguments are used as attributes. Input values contained in HTTP request parameters are automatically completed.

<input name = "first_name" />
<input name = "first_name" value = "Default name" />
<input name = "employed" type = "checkbox" />
<input name = "country" type = "radio" value = "germany" />

Base tag

You can easily write a base tag using the base_tag function, which is a tag helper.

<%= base_tag%>

It will be expanded to the following tags.

<base href = "http: //localhost/cgi-bin/myapp.pl" />

Related Informatrion