How Necessary is $parent Within a Server Action Repeat?

I have a server action structured like this:

Database Query contact
repeat something
   Set Value this_text = {{this_text.replace('[First Name]', contact.first_name)}}

This is working completely okay, but I believe it technically needs to have a $parent in front of contact.first_name because the Set Value is within a repeat.

Question 1 - Is this correct?

In this case it should read:

Database Query contact
repeat something
   Set Value this_text = {{this_text.replace('[First Name]', $parent.contact.first_name)}}

I am finding that both code examples are working.

Question 2 - Should I add the $parent to my 50 lines of code of this nature to be future proof with Wappler?

This situation came about because I moved the Set Value actions to be within the repeat… and of course Wappler does not change the code within them to include the $parent when I move the actions.

Normally $parent is not needed. If the variable is not found in the current scope then it will look in the parent scope and get it from there.

The only case that you need $parent is when you have a variable with the same name in both scopes and you want to access the value from the one in the parent scope. Like in your case when a variable contact should exist in the repeater scope, but you wanted to get the value from the contact variable outside the repeater.

1 Like

Thanks for the rapid clarification @patrick!