elixir-web / weber

[WiP] Web framework for Elixir inspired by Rails [#WeberMVC at freenode]
http://elixir-web.github.io/weber/
MIT License
370 stars 33 forks source link

Using layout in controller #201

Open tomkadwill opened 10 years ago

tomkadwill commented 10 years ago

I want to use a layout as a base for all of my views so my controller looks like:

defmodule ElixirWeberTest.Main do

  use Weber.Controller
  layout "application.html"

  def index([], _conn) do
    {:render, [], []}
  end

  def show([], _conn) do
    {:render, [foo: 'foo'], []}
  end
end

When I load the view for show get a page in the browser that looks like:

hi <%= 'Tom' %> <%= @foo %>

If I remove use Weber.Controller and layout "application.html" then the view loads correctly displaying values in place of the tags.

Not sure if this is a bug or if I am doing something wrong. If this is confirmed as a bug then I am happy to work on a fix :)

rcdilorenzo commented 10 years ago

Yes. I believe this is an issue. I think I've actually seen it before. I do know that the workaround is to replace the content_for_layout with an evaluation of the string passed in:

<%= EEx.eval_string @content_for_layout, assigns: assigns %>

Therefore, the layout manager probably just needs to make sure that it evaluates the content passed in. If you can make a pull-request for this, that would be fantastic.