Can variables be dynamic?

I think this is related to a question I asked long ago, for which there didn’t seem to be a ‘Wappler solution’. However, this recent thread looked like it might offer a solution (I couldn’t get it to work but it might be worth looking at more closely - if indeed it is relevant to what you need).

To get the best final result, I suggest the following:

  1. First, let’s think together about improving your structure. Because it is the improvement of the structure that gives a qualitative and long-term effect in the work. The work with logic is simplified, the tasks of scaling in the future are simplified, and the work becomes more stable and flexible. The structure I proposed above can work not only with binary questions. The proposed structure can serve any questions and even a unique questionnaire (when each user has unique questions that differ from the questions of other users). If, after all, the proposed structure cannot serve some specific task, tell us more about this task, we will try to optimize the structure for it.

  2. If, after all, the problem can not be solved by optimizing the structure of data tables. Let’s move on to the solution at the logic level. We will try to find a solution based on your table structure.

Can I simplify my question?

I want to change it like this:

Normal code generated by Wappler…

dmx-show="( == FieldAnswer)"

I want the subconQuest1 to instead be pulled in from a field in the loop, eg:

dmx-show="({{loopQuestion}} == FieldAnswer)"

but I’m not sure what the syntax should be. I’ve shown it here in curly braces purely to illustrate my intention.

@Teodor or @patrick, how can I achieve this?

Ooh, that looks very interesting. It implies what I want to achieve is possible but I can’t see exactly how I should go about it.

Before I give up on my plan and do it a completely different way, could someone please confirm if this is or isn’t possible?

In principal, it seems possible, given that there seems to be a way for Wappler to parse dynamic variables, using the custom formatter included in one of the threads I mentioned. Did you try this? I couldn’t get it to work. Perhaps there was an error in the formatter, but presumably @patrick suggested it because he knew it was possible. I think it is/would be a great feature.

1 Like

I did look at that thread but wasn’t able to solve the issue with it.

I keep thinking that what I want must be possible and I can reduce the finished code to a fraction of the size by using this technique, and make ongoing maintenance so much easier, but I’ve tried lots of ways but without success.

I agree that Patrick is the one to show how it’s done or confirm that it’s not possible. I’ve now started doing it a completely different way which will take much longer to complete (it’s a huge questionnaire which is why I want to do it using data) but at least I know it will work.

Would love to do it this way, though.

Tom, if I understand your need correctly, then the solution to your problem is quite simple. You should save your string not in a variable, but in an array with conversion to this very array.

It looks like this:

<dmx-array id="arr1"

Then just create a repeat that uses dmx-repeat:repeat1="arr1.items" as the data source, and as the text dmx-text="$value".

Jon, if I understand your task correctly (I adhere to the understanding that you need to compare and show the correct answers from each user, if this is not the case, correct me), then you have a more complex task.

I don’t quite understand when you talk about a loop, what do you mean here?:

Sorry @Mr.Rubi, when I refer to ‘loop’ I probably should say ‘repeat’.

Repeat always works with an array. Combining the fields quQuestion1, quQuestion2, quQuestion3, quQuestion4, quQuestion5 into an array and then using it in a repeat is not a problem. The problem is to correctly match the rows from this array with the correct questions. After combining the fields into an array, we will not know which row belongs to which question.

Thanks for this suggestion. It’s an interesting idea but unfortunately I don’t think it’s a solution. The example I gave in that thread from 2019 was a simplification.

In this case, I wanted to retrieve a value stored in single field in a database and have Wappler parse this rather than treat it as static text. The single value is in effect a template - perhaps something like this:
(I used an image as I couldn’t get the code to display correctly)

The code could actually originate from anywhere - not necessarily as described above. This can of course be done using PHP as the code is included in the page before Wappler parses it. I assumed it wasn’t possible in Wappler, until I saw the other thread I referenced above, where @patrick seemed to offer a solution for something similar, but I couldn’t get this to work.

I think there would be many uses for such a feature (eg as discussed in this current thread). Really, it’s just a general request - an option to get Wappler to treat a string as text to be parsed, in the same way as dmx-html tells Wappler to treat dynamic data as HTML. (Perhaps I should create a request for this - unless it’s already possible.)

Create a request :+1:. It’s something that would be really handy - unless it’s already possible and we just don’t know how to do it!

Yes, Tom, I initially misunderstood your task. My solution is not suitable for this.

Perhaps this is deja vu, but as if 3-4 weeks ago I read a topic in which this question was raised. I couldn’t find this topic. Such a function would really be useful in cases where it is necessary to implement CMS functionality in a project. I myself will need to implement this functionality in the project, because the client wants a built-in editor in his CRM, in which he can configure not only the contents of certain sections, but also the design of elements in these sections. Therefore, I will also need the ability to read the code written to the database and recognize areas with dynamic data in the code.


It’s good to hear your requirement is similar to mine - and probably to @sitestreet’s too. For anyone developing a system where such flexibility is required, a feature like this would be invaluable -particulary if such a system might be used by multiple businesses, where different users within those businesses might need their own options to customise templates etc.

I’ll create a request, but out of interest are you using PHP? I am. I wonder if it’s something that is already possible with NodeJS (about which I know very little).

Yep, I’m using PHP.

I know I’m late to the party and sorry but really not got time to read all the posts, but is this what you are looking for?

<dmx-value id="var_a2_id" dmx-bind:value="'a2_id_' + carparts_id + '_' + $index"></dmx-value>

Hi Neil. It’s hard to see if your suggestion is what I’m after or not. The key summary for me is this:

Almost everywhere now I use NodeJS in projects. I have only one project left in PHP, but I plan to transfer it to NodeJS, if the customer resumes work on it.

As for the possibilities in NodeJS for this functionality, I have not yet delved into this issue, but I suspect that everything is the same as in PHP. It seems to me that the implementation of this functionality lies on the AppConnect side, so the server language is not so important. In other words, to achieve the correct interpretation of the code, you need to either expand the capabilities of AppConnect, or create custom solutions.

Could you not use something like this?

dmx-show="([loopQuestion] == FieldAnswer)

(use square bracket instead of dot notation)


Ben, gave the right answer.

For context: