Hi Bruno,
What i am trying to do is take opportunity of the great feature that snippets are.
Yes, a snippet is parsed before page load, but it does runs again when i click the button. So, the way I see it, snippets are some sort of a link/pipe... between resource and the server.
I am already using snippets on page load to get data from the database, and I love it. I am also using ajax to call a snippet through a page with an empty template and it works fine, I am just thinking that it would be easier and faster if i could connect directly to the snippet with dynamic data through javascript/jQuery events.
I think I am making progress, but I am still having issues.
Consider the following code:
jQuery( "#usr_save" ).on("click", function() {
var new_val = jQuery("#someinputid").val();
var test = '[[!testsnippet? &msg=`'+new_val+'`]]';
console.log(test);
})
and my snippet:
If I just run the code like this, it will return what ever is typed in the text input (good).
However I cannot manipulate the $msg variable inside the snippet.
example, let say that I type "this_is_a_new_val" into the text box, if I try to get part of $msg with explode like this:
<?php
$t = substr($msg, 0, 30);
$a = explode("_", $t);
return $a[1];
it will not return the expected "is" but it will return "val+", meaning that internally the snippet interpret what is inside the ticks.
Note: I need the substr line or it will generate an error.
Any idea on how to get to the dynamic string will be greatly appreciated.
Thank you for your help