View helpers for rendering Plato content in Phoenix templates.
Usage
In your view or my_app_web.ex:
import Plato.HelpersThen in your templates:
<%= plato_content("homepage", :title, otp_app: :my_app) %>
<%= plato_list("blog_post", otp_app: :my_app) do |post| %>
<article>
<h2><%= post.title %></h2>
</article>
<% end %>
Summary
Functions
Fetch and return a field value from unique content.
List all content for a schema and render each item with a function.
Fetch content and render it with a function.
Functions
Fetch and return a field value from unique content.
Returns the field value if found, nil otherwise.
Examples
In templates:
<%= plato_content("homepage", :title, otp_app: :my_app) %>
#=> "Welcome to My Site"
<%= plato_content("homepage", :tagline, otp_app: :my_app) %>
#=> "The best site ever"Returns nil for missing content:
iex> Plato.Helpers.plato_content("nonexistent", :title, repo: Plato.Repo)
nil
List all content for a schema and render each item with a function.
Examples
<%= plato_list("blog_post", otp_app: :my_app, fn post -> %>
<article>
<h2><%= post.title %></h2>
<p><%= post.excerpt %></p>
</article>
<% end) %>
Fetch content and render it with a function.
Useful when you need to render referenced content with custom markup.
Examples
<%= plato_render("homepage", :hero, otp_app: :my_app, fn hero -> %>
<img src="<%= hero.image_url %>" alt="<%= hero.alt_text %>" />
<% end) %>