How to create a strong element inside p

In haml, how do I make the following incredibly simple HTML:

<p>Results found for <strong>search term</strong> 

where is the “search term” really a Ruby variable called @query ?

I am trying to do the following:

 %p results found for <strong>= @query</strong> 

But that means = @query literally. If I try:

 %p results found for <strong> = @query </strong> 

then the term of the request is displayed correctly, but is in a new line.

Also, I am wondering if there is a better way to render <strong> in haml, keeping everything in one line.

I know haml documentation , but as far as I can see, there is no example of using a simple built-in ruby ​​variable.

----- UPDATE -------

The following code works and shows how to use a variable that is not in the tags:

  %p = @trials_found_count results found for %strong= @query 

But I find it really unreadable - it's hard to say that it only displays one line of HTML without adding a comment above.

Is there a way that I can put all this code on one line? Or is it how the haml works?

+4
source share
3 answers

HAML is a space. Nested tags follow the line below and at the same level as the tag above. The built-in Ruby from which you want to display the output is opened with '='. Built-in Ruby that you do not want to display, such as the beginning of loops, uses a '-'. These values ​​are equivalent to <% =%> and <%%> respectively in erb.

What you want will look like this:

 %p results found for %strong= @query 

To create html:

 <p>results found for <strong>@query</strong></p> 

It should be noted that the '=' to start a Ruby evaluation can only appear at the beginning of a line or after a tag declaration, and that only one tag declaration can appear in each line. The Ruby Evaluation section of the link you referenced includes inline Ruby and a haml tutorial that contains inline ruby ​​and many other haml basics:
http://haml-lang.com/tutorial.html

+5
source

Here's how I would do it:

 %p No results found for <strong>#{h @query}</strong> 
+4
source

I'm not sure, but you may need inextricable space to save the space between the for and <strong> parameters

 %p results found for&nbsp; %strong= @query 
+1
source

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


All Articles