Skip to content

Instantly share code, notes, and snippets.

@smpallen99
Last active April 17, 2017 13:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save smpallen99/16a04397ac5ce5be6876 to your computer and use it in GitHub Desktop.
Save smpallen99/16a04397ac5ce5be6876 to your computer and use it in GitHub Desktop.
Phoenix content_for prototype
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Hello Phoenix!</title>
<link rel="stylesheet" href="/css/phoenix.css">
</head>
<body>
<div class="container">
<div class="header">
<ul class="nav nav-pills pull-right">
<li><a href="http://www.phoenixframework.org/docs">Get Started</a></li>
</ul>
<span class="logo"></span>
<%= yield(:introducting) %>
</div>
<%= @inner %>
<div class="footer">
<p><a href="http://phoenixframework.org">phoenixframework.org</a></p>
</div>
</div> <!-- /container -->
</body>
</html>
defmodule ContentFor do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
spawn fn ->
:ets.new :phoenix, [:public, :named_table]
receive do
:exit ->
:ok
end
end
# ...
end
end
<%= content_for :introducting do %>
<div class="jumbotron">
<h2> Introducing: <%= @name %> </h2>
</div>
end %>
<div class="jumbotron">
<h2>Welcome to Phoenix!</h2>
<p class="lead">Phoenix is an Elixir Web Framework targeting full-featured, fault tolerant applications with realtime functionality.</p>
</div>
<div class="row marketing">
<div class="col-lg-6">
<h4>Resources</h4>
<ul>
<li>
<a href="http://hexdocs.pm/phoenix">Docs</a>
</li>
<li>
<a href="https://github.com/phoenixframework/phoenix">Source</a>
</li>
</ul>
</div>
<div class="col-lg-6">
<h4>Help</h4>
<ul>
<li>
<a href="https://github.com/phoenixframework/phoenix/issues?state=open">Issues</a>
</li>
<li>
<a href="irc://irc.freenode.net/elixir-lang">#elixir-lang on freenode IRC</a>
</li>
<li>
<a href="https://twitter.com/chris_mccord">@chris_mccord</a>
</li>
</ul>
</div>
</div>
defmodule ContentFor.View do
use Phoenix.View, root: "web/templates"
require Logger
using do
quote do
import ContentFor.Router.Helpers
use Phoenix.HTML
end
end
def content_for name , do: block do
:ets.insert :phoenix, {name, block}
nil
end
def yield(name) do
fun = :ets.lookup(:phoenix, name)
|> Keyword.get(name)
|> Phoenix.HTML.safe
end
end
@aliabbas-2012
Copy link

Thanks awesome tutorial
Following function doesn't exist in phoenix
Phoenix.HTML.safe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment