[Solved] How to Process Nested Dynamic Content in Custom Functions?

Hi there!

A more advanced question. I hope there is a solution for this.

I created a custom dynamic content that accepts the key and uses that in the function. However, I would like it to accept the rendered version of nested dynamic content.

Normally the DC looks like this:

{{ wp_members.has_access({"membership":"key-value"}) }}

When used with nested DC it looks like this:
{{ wp_members.has_access({"membership":"{{ looper.field({\"key\":\"cursus\"}) }}"}) }}

The problem is that the function receives {{ looper.field({\"key\":\"cursus\"}) }} as the key-value instead of what the looper-field refers to (“key-value”).

Is there a way to send the rendered version of dynamic content to a custom function? Or is there another or better way to do this?

Many thanks in advance!

When the Twig tags have started you no longer need to add in {{ unlike inner Dynamic Content. So it would look like the below. Adding in the double quotes around the looper field is also unnecessary and will cause issues.

{{ wp_members.has_access({"membership": looper.field({"key": "cursus"}) }) }}

Or access the looper.item directly.

{{ wp_members.has_access({"membership": looper.item.cursus }) }}

Let us know if this helps and have a great day.

Dear Charlie,

Thank you so much! That was exactly the mistake I made. It works now! Thew new syntax is much easier. Great improvement. It will take some time to convert all my dynamic content habits to Twig. :sweat_smile:

1 Like

You are most welcome @Dagaloni

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.