Hello, I am trying to pass dynamic data using {echo} to a JavaScript function using the Bricks interaction argument feature.
Passing the {post_title} works fine, but trying to pass a value using the {echo} dynamic data feature doesn’t work. Console.log shows the arguments passed using the {echo} function as null.
In the screenshot I have changed the name of the function for OPSEC purposes, but the function is used in different areas of the page in working on the page in Rich Text modules. The function returns a related post_id. I’ve added the function name to the “bricks/code/echo_function_names” hook as well.
Thank you for your response! This is a Bricks Builder Extras element, so I’m assuming that it is a bug with that element. I did try adding your simple PHP function, and it still didn’t output.
This can be closed out. Thanks again for the help!
But when I open the page on front end, the PHP function is called for all the posts in query loop at the time of page is loaded. So it doesn’t wait until I click on the Div element.
Does anyone know what am I doing wrong please?
so, the issue is that the {echo:myPHPfun({post_id})} gets executed on page load, for all items? This looks correct to me because the PHP part is executed on the server side - so before page load.
What is executed on item click, is the interaction, which is JS part.
Please let me know if that’s not it.
Thanks,
Matej
I see. You could try to add {post_id} as a data attribute to the element, and you don’t pass this parameter directly to JS function. You can then instead read the parameter (post ID) from the data-attribute.
The problem is something else. I have an query loop and want to call PHP function when I click on the specific element of the query loop.
A don’t know how to achieve this so I tried to workaround that by Interaction “javaScript (function)” but I didn’t know how it works and that’s not the correct way for me.
Now I know that my thougts were bad so it’s not problem of this topic.