Genie Discord forum

Author AvatarXergon
2/22/2023, 1:09:30 PM

It is possible to use these <% %> in a space where all html <> are closed:

<a href="$(linkto(:show_dashboard))" class="nav-link" aria-current="page">
  <i class="bi bi-speedometer2 me-2" width="16" height="16"></i>
  Dashboard <% if false "true" else "false" end %>
</a>

But when I try to use it in order to add a class for instance, the %> gets used to escape the html tag.

<a href="$(linkto(:show_dashboard))" class="nav-link <% if true "active" else "text-white" end %>" aria-current="page">
  <i class="bi bi-speedometer2 me-2" width="16" height="16"></i>
  Dashboard
</a>

Is there a workaround? I could get the same behaviour with js probably but still. How can we use the julia snippets in a tag?

Author AvatarPere
2/23/2023, 10:42:54 AM

<% %> is used for multi-line interpolation whereas $(...) is for single-line. I see that %> closes the tag, which I don't think should be happening; I'll open an issue about this. In the meanwhile, try with $().

I tried setting the class as

<a href="" class="nav-link $( true ? "active" : "text-white" )" aria-current="page">
  <i class="bi bi-speedometer2 me-2" width="16" height="16"></i>
  Dashboard
</a>

but it fails with LoadError: syntax: cannot juxtapose string literal . This works in the REPL

julia> "nav-link $( true ? "active" : "text-white" )"
"nav-link active"

@abhimanyuaryan , should we open an issue about this?

In the meantime, one workaround is storing the classes in a variable in the julia code, and then interpolate in the HTML file:

classelect = true
trueclass = "active"
falseclass = "text-white"

.

<a href="" class="nav-link $( classelect ? trueclass : falseclass )" aria-current="page">
  <i class="bi bi-speedometer2 me-2" width="16" height="16"></i>
  Dashboard
</a>
Author AvatarXergon
2/23/2023, 7:24:29 PM

ah, my mistake, I am still learning more and more about Genie.