How to mix text and elements

If I want to output something like the following in Seed:

<a href="...">a link</a>, <a href="...">another link</a>

do I need to put the comma and space (, ) in a <span> element? I tried text! in my view function:

a![ attrs! { At::Href => "..." }, "a link" ],
text![ ", " ],
a![ attrs! { At::Href => "..." }, "another link" ],

But this outputs:

<text xmlns="http://www.w3.org/2000/svg">, </text>

And that doesn’t show up at all. Of course, I could replace text with span and I’m sure it’ll work. Is that the way we’re supposed to mix text and elements? Is there a way to have inline elements within text content?

Try to use regular Rust Strings / str or Node::new_text(...) when you want to mix elements and texts in homogeneous containers like vectors.

1 Like

Node::new_text() worked exactly as I’d hoped, thanks. Regular Rust String or str didn’t work as Rust was expecting a Node:

expected enum seed::virtual_dom::node::Node<Msg>
found struct std::string::String

I forgot to mention macro plain!("my text"). It’s just shortcut for Node::new_text.

1 Like