SmartIndentationEngine.Template (SmartIndentationEngine v0.1.0)

View Source

Provides the ~TT sigil to compile templates with the SmartIndentationEngine, and the include/2 macro for rendering partials.

Summary

Functions

Renders a partial defined by the given function name.

Compiles a template string using the SmartIndentationEngine.

Functions

include(partial_name, args \\ [])

(macro)

Renders a partial defined by the given function name.

Example

<%= include :partial %>
<%= include :partial, name: true %>

This will call partial/1 function with the current assigns.

sigil_TT(arg, list)

(macro)

Compiles a template string using the SmartIndentationEngine.

Example

defmodule MyApp.Template do
  import SmartIndentationEngine.Template

  def render(assigns) do
    ~TT"""
    <%| case @lang do %>
      <% :fr -> %>
        <%= include :french %>
      <% _ -> %>
        <%= include :english %>
      <% end %>
    """
  end

  def french(assigns) do
    ~TT(Bonjour <%= @name %>)
  end

  def english(assigns) do
    ~TT(Hello <%= @name %>)
  end
end

MyApp.Template.render(lang: :fr, name: "John")
# => "Bonjour John"