Bootstrap link vs phoenix link `<%= link ..`

I have integrated bootstrap 4 successfully into my project, then I am trying to do

<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>

I am trying to use phoenix template system , so I changed

<%= link "Home", to: page_path(@conn, :index), class: "nav-link" %>

How can I put
<span class="sr-only">(current)</span> into the phoenix template system.

2 Likes

Roughly like this:

<%= link raw(~s'Home <span class="sr-only">(current)</span>'), to: page_path(@conn, :index), class: "nav-link" %>

Phoenix.HTML.raw/1

3 Likes

This not work for me

Thank you @NobbZ , it works for me now.

I forget ~s

Yeah, I only realised after posting, that there were quotes in the string, so I had to edit it into a sigil variant.

This should work as well.

<%= link to: page_path(@conn, :index), class: "nav-link" do %>
    Home <span class="sr-only">(current)</span>
<% end %>
9 Likes