Using dynamic values within set value -server side

Does anyone know if I can put dynamic content within a block of text read from a database field?

I have a table that stores the HTML “sections” to construct an email, by combining the various HTML sections, that I then send to users (order confirmations etc.).

This is in a server API where I combine the various HTML snippets and add repeat sections (such as lists of products ordered), to build the email body and then send but I would like to replace some static values in the HTML snippets with dynamic values (e.g. the delivery address, contact details etc).

An example of a bit of the HTML snippet would be -

<div class="col"
                                    style="display:inline-block;width:100%;max-width:270px;vertical-align:top;text-align:left;font-family:Arial,sans-serif;font-size:16px;line-height:22px;color:#363636;">
                                    <h3>Your Invoice Address</h3>
                                    <p>invoice Name</p>
                                    <p>invoice Line1</p>
                                    <p>Invoice Line2</p>
                                    <p>Invoice Town</p>
                                    <p>Invoice County</p>
                                    <p>Invoice postcode</p>
                                    <H4>Invoice Contact Details</H4>
                                    <p>Invoice Contact Name</p>
                                    <p>Invoice Contact Number</p>
                                    <p>Invoice Contact Email</p>
                                </div>

I would like to replace all the order elements (e.g. “Invoice Name”, “Invoice Line1”, “Invoice Line2” etc.) with fields from my orders table.
I have queried the table and have the fields but can’t figure out how to add a reference to the queried fields within the stored HTML snippet so I don’t have to “build” the HTML

Tried {{order_and_user.invoice_name}} and +{{order_and_user.invoice_name}}+ and dmx.parse('order_and_user.invoice_name') but can’t seem to guess the correct format.

Is this possible?

This sort of functionality is possible via custom query or a custom module.
In query, you could use find replace functions. It will be complicated.
In custom module, you can parse the data returned from db to replace those expression bindings.

Hi Paul
Perhaps you are looking for something like this?

Thanks guys,

That is how I am doing it at the moment which is a bit involved but works, I was hoping for a more elegant (lazy) solution before I got too involved.

lucking to content is not too embedded in the HTML and I know the number of placeholders to replace in advance so I can fairly easily work through with a handful of variables and some conditionals.

Cheers,
Paul

Sendgrid + JSON + wappler + handlebars works a treat. There’s a free tier as well … Ups your email game big timr

1 Like