How to embed HTML inside partial (using HAML)

I have a partial one that represents the title that I want to place on some of my pages. However, each page has a different name. I want to "insert" this header into a partial one.

Here is what I am trying to do, although it does not work:

= render: partial => "section_head_top"
    % span (id = "section_head_header") Apply
    = render: partial => "section_head_divider"

Part_head_top:

  #section_head
      #section_head_top
          #section_head_content

I want the% span line to be inside the div of the section_head_content section. I get a "syntax error, unexpected keyword_ensure, expecting $ end" for two lines outside of my code (even if the bottom is removed).

How it's done?

Thank!

+3
source share
1 answer

I would recommend using a local variable in partial. For example, if your partial code looks something like this (_section_head_top.haml):

- title || = 'Default Header'
#section_head
  #section_head_top
    #section_head_content
    % span (id => "section_head_header") = title
    = render: partial => "section_head_divider"

You can call this from your code:

= render: partial => "section_head_top",: locals => {: title => 'Apply'}
+1
source

Source: https://habr.com/ru/post/1790227/


All Articles