HTML Tags
Phlex::HTML
comes with methods that correspond to the most common HTML tags. Youβve seen the h1
tag in the previous section.
Content
You pass content as a block to a tag method. If the return value of the block is a String
, Symbol
, Integer
or Float
and no output methods were used, the return value will be output as text.
Attributes
You can add attributes to HTML elements by passing keyword arguments to the methods.
Underscores _
are automatically converted to dashes -
for Symbol
keys. If you need to use an underscore in an attribute name, you can pass it as a String
.
Hash attributes
You can pass a Hash
as an attribute value and the Hash will be flattened with a dash between each level.
Boolean attributes
When an attribute value is true
, the attribute name will be output without a value; when falsy, the attribute isnβt output at all. You can use the strings "true"
and "false"
as values for non-boolean attributes.
The template tag
Because the template
method is used to define the view template itself, you'll need to use the method template_tag
if you want to to render an HTML <template>
tag.
Registering custom tags
You can register custom elements with the register_element
macro. The custom element will only be available in the view where it is registered and subclasses of that view.