I have a breadcrumb component that can override the default separator as below:
def breadcrumb_separator(assigns) do
~H"""
<li role="presentation" aria-hidden="true" class={["[&>svg]:size-3.5", @class]} {@rest}>
<%= if length(@inner_block) > 0 do %>
<%= render_slot(@inner_block) %>
<% else %>
<.iconify icon="heroicons:chevron-right-solid" />
<% end %>
</li>
"""
end
It feels a bit hacky that I’m using length/1
to test if there’s any content passed to the slot. Is there an idiomatic way to test if a component has content in its slot? Testing it directly with <%= if @inner_block do %>
always renders true, presumably because the slot exists?