I'm searching for a way to add a stylesheet link to the layout's head of a HAML template.
My layout:
!!!
%html
%head
/ some stuffs
%body
= yield
My yielded template:
/ some other stuffs...
/maybe a function like this in order to inject 'my_stylesheet' link in layout
= content_for_head 'my_stylesheet'
Is it possible to do something like that?
There are 2 ways you can go about it. One is to use Sinatra's own content_for
gem, or bundle ActionView, which will give you access to Rails' content_for
method.
The second option is to do a manual check in the layout, and include the CSS there:
# in your HAML template:
- if request.path_info == '/hello-world'
%link{:rel => :stylesheet, :type => :"text/css", :href => "/assets/css/my_stylesheet"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With