Fork me on GitHub
#reagent
<
2023-01-20
>
Uli10:01:18

Hi there, trying to find a way to save hiccup like code in database and render it from there. e.g. I have info-field, where I'd like to be able to format stuff or add elements, tables, lists etc. This I'd like to save this to the database as a string. My problem is, that I'm not able to render the string afterwards, it gets html-escaped and displayd as the given string, but i dont want: [:h1 "Hello world"] I'd like to have Hello world (cannot simulate h1 here, but I think you get what i mean) Can you give me a hint, how to render it?

p-himik11:01:30

The above works only if you save HTML as a string. For Hiccup, you can serialize it as EDN or Transit before storing and deserialize upon retrieving so you get a proper Hiccup vector and not a string.

p-himik11:01:09

Also note that you won't be able to make that Hiccup use any CLJS code without hassle. I.e. in plain code you can write stuff like [:button {:on-click #(...)} "Submit"], but it won't get serialized properly. Best you can do is [:button {:id :submit} "Submit"] and then attach the onClick handler dynamically. Given that, I'd reconsider the whole approach. If it's possible, it would be much better to have a registry of possible elements and their settings and then use IDs or whatever from that registry when storing the current configuration in the DB.

Uli11:01:29

Ok, thanks. It's not, what I hoped for, but ok, Rethinking most of the time is a good thing though...