Dennis

Dennis

Using template engine without Phoenix?

Disclaim: I am rather new to Elxiir and Phonix, though I do have some experience in other languages.

As far as I understand, a template engine, or its compile function, is something that takes a template and assigns, replaces some specially marked elements in the template, and returns a string. So theoretically this function can be used without Phoenix and its model-view-controller architecture. Unfortunately, I cannot seem to find any example of applying it this way. The documentation only says

compile(template_path :: binary, template_name :: binary) :: Macro.t

Can anybody give me an example of how to apply this function? I tried Phoenix.Template.EExEngine.compile('.', "a.eex"), but got the error message

(ArgumentError) template paths in Phoenix require the format extension, got: a.b
    (phoenix_template 1.0.4) lib/phoenix/template/eex_engine.ex:19: Phoenix.Template.EExEngine.options_for/1
    (phoenix_template 1.0.4) lib/phoenix/template/eex_engine.ex:9: Phoenix.Template.EExEngine.compile/2
    iex:43: (file)

Most Liked

al2o3cr

al2o3cr

IMO that particular boundary isn’t intended to be used separately - compile/2 is an interface for template engines to “plug into” Phoenix.Template.compile_all and similar functions, so there’s a lot of supporting code needed around it.

The underlying library, EEx has significantly better documentation and would be a better place to start.

Last Post!

D4no0

D4no0

The last time i stole got inspired from phoenix embedded engine, it was straightforward. You can look at the source of ~H sigil here.

Since this sigil is html aware, I think it has more than just a eex under the hood. I would just copy the sigil code with those engines to avoid headaches. If you are just interested in a engine that just escapes html, look at older versions of phoenix, the old ones they used were simple.

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New

We're in Beta

About us Mission Statement