Вопрос

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