Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a stylesheet to the layout's head of a HAML template in Sinatra?

Tags:

sinatra

haml

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?

like image 496
szymanowski Avatar asked Jul 08 '13 00:07

szymanowski


1 Answers

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"}
like image 113
Arman H Avatar answered Sep 22 '22 06:09

Arman H