How to add a stylesheet to the layout of a HAML template chapter in Sinatra?

I am looking for a way to add a link to a stylesheet to a HAML template layout.

My layout:

!!! %html %head / some stuffs %body = yield 

My 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 this?

+8
sinatra haml
source share
1 answer

There are two ways to do this. One of them is to use your own content_for Sinatra stone or link an ActionView that will give you access to the Rails content_for method.

The second option is to do a manual layout check and include CSS there:

 # in your HAML template: - if request.path_info == '/hello-world' %link{:rel => :stylesheet, :type => :"text/css", :href => "/assets/css/my_stylesheet"} 
+13
source share

All Articles