Rendering strings that reference variables

Hi,

I was wondering if there is a way to have a string stored in a database that contains "references" (I think the proper term is bindings?) to variables rendered after interpreting those references instead of as a string.

Assume the following:

  1. I have a page with a server connect sc1 that returns the a value called radius
  2. I have a variable call pi, that contains the value 3.14
  3. I have a paragraph that looks like this:

    Perimeter: {{sc1.data.radius * pi.value * 2}} cm

When the page is rendered, and ignoring any syntax error in my example and assuming that sc1 returns a radius of 10, the following will be shown:

Perimeter: 62.8 cm

Imagine that now I wanted to keep the text in 3 above in a database table, and that I have a server connect sc2 that retrieves the value of that string.

If I invoke sc2 and put the results on the page (something like sc2.data.stringtoshow, the page now shows the string as I saved it, i.e., without interpreting the values of the variables. It would look like

Perimeter: {{sc1.data.radius * pi.value * 2}} cm

I sort of understand why this happens but I'd like to know if there is a way of storing in a database table a string that contains references to variables, which can be later interpreted and rendered as the results of the reference and not as a string.

Many thanks,

Alex

Hi,

A very interesting approach. Although, saving params in DB and getting values via server action would be a better desgin in my approach.

Anyways, back to the point: This is possible, but not natively via Wappler UI yet. You will have to rely on JS for this.

Using AppConnect/DMX’s dmx.parse function, you can concatenate such bindings/expression strings in JS and get it rendered on the page.

It will be a bit elaborate and a bit slow as you keep adding bindings like these.

Another option I can suggest is custom formatters. That is also basically JS, but it will result in a more cleaner code.

Both the options will have their limitations as such kind of binding won’t be usable in repeats.

1 Like

Thanks Sid for the prompt response.

For a variety of reasons, the main one being my ignorance of how to do it :slight_smile: , I don’t want to write custom code.

My use case for this feature is for sections of a page that have mostly static text BUT that also have some dynamically generated strings in the middle of it. In my particular case, this is used in an attestation page where the wording (static and dynamic) may need to be changed often until all the sponsors agree on the text. As it stands, we need a Production deployment every time instead of changing text in a database.

The latter approach, however, only works well if static text is used, thus my question.

I will repost this as a feature request: To add native option to Wappler (let’s call it “Inner Parsed” for now) to allow parse dynamic content like one retrieved by a server action, parsed before rendering it in the browser. This “Inner Parsed” option will be show right beside the “Inner HTML” and “Inner Text” options that appear under Dynamic Attributes > Display.

Many thanks!

This is something like INDIRECT() in msft excel. Maybe @patrick would consider such a function for Wappler!
I can see a use case for this when we need to allow end users to put in their custom formulas or something in runtime!