Skip to main content

append

Function append 

Source
pub fn append(target: &str, html: &str) -> String
Expand description

Builds a message that inserts html at the end of the element with id target (htmx beforeend).

The fragment is wrapped in an element the browser can parse it in (a <tr> goes in a <tbody>, an <li> in a <ul>, and likewise for other table parts, options and <dt>/<dd>; anything else in a <div>) carrying hx-swap-oob; htmx drops the wrapper. target is escaped; html is sent as is, so escape user content in it (askama templates do). Pure: no I/O until you broadcast it.

ยงExamples

assert_eq!(
    ocre::realtime::append("comments", "<li id=\"comment_2\">Hi</li>"),
    "<ul hx-swap-oob=\"beforeend:#comments\"><li id=\"comment_2\">Hi</li></ul>"
);