문제

I try to convert a ramaze app to padrino(0.12.1) Current problem that I have is instance variable in padrino/sinatra controller can't be read by liquid template.

controllers/main.rb

Myproject::App.controllers :main do
  get :index, :map => '/' do
    @name = 'foo'
    render 'main/index'
  end

views/layouts/application.liquid

...html code here...
 Testing
 {{ content }}
...html code here...

views/layouts/main.liquid

Hello {{ name }}

Result should be

"Testing Hello foo", but I only get "Testing Hello".

Any clue? Tnx.

도움이 되었습니까?

해결책

Liquid doesn’t allow evaluating Ruby code as part of the templates, which includes accessing instance variables. You can set locals through a hash:

render 'main/index', :locals => { :name => 'foo' }

foo will then be available in the template.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top