Pass HTML string to partial or view #4231
Answered
by
RomainLanz
MightyMoud
asked this question in
Help
-
Hi guys, I'm trying to render HTML that is coming from a different server. So I have a placeholder in my edge template looking like this <div class="text-[--text-muted]">
{{msg.aiMessage}}
</div> The problem is that this is not being parsed as HTML by browser, it's rendered as string inside the div. So I tried to do this: Define the template as raw string: const template = `<div hx-swap-oob="beforeend:.chat-body">
<div class="p-2 bg-[--neutral-300] rounded-md flex flex-col gap-2 ">
<div class="text-[--text-muted]" data-controller="welcome" data-course-slug="${
course.slug
}">
${msg.aiMessage.replace('\n', '<br/>')}
</div>
</div>
</div>
` then use renderRaw This does work, but it also means I maintain my partial as a string now... Any better way to do this? |
Beta Was this translation helpful? Give feedback.
Answered by
RomainLanz
Aug 27, 2023
Replies: 1 comment 1 reply
-
Hey @ms-mousa! 👋🏻 You have to use 3 curly braces not to escape the given string. <div class="text-[--text-muted]">
{{{ msg.aiMessage }}}
</div> |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
MightyMoud
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @ms-mousa! 👋🏻
You have to use 3 curly braces not to escape the given string.
📚 https://docs.adonisjs.com/guides/views/templating-syntax