我正在寻找一种方法来将样式表链接添加到HAML模板的布局头部.
我的布局:
!!!
%html
%head
/ some stuffs
%body
= yield
Run Code Online (Sandbox Code Playgroud)
我的模板:
/ some other stuffs...
/maybe a function like this in order to inject 'my_stylesheet' link in layout
= content_for_head 'my_stylesheet'
Run Code Online (Sandbox Code Playgroud)
有可能做那样的事吗?
Arm*_*n H 15
有两种方法可以解决它.一种是使用Sinatra自己的content_forgem,或捆绑ActionView,它将使您可以访问Rails的content_for方法.
第二个选项是在布局中进行手动检查,并在那里包含CSS:
# in your HAML template:
- if request.path_info == '/hello-world'
%link{:rel => :stylesheet, :type => :"text/css", :href => "/assets/css/my_stylesheet"}
Run Code Online (Sandbox Code Playgroud)