Question

I am using mustache PHP to render my html files and everything works correctly except in one case. There is a situation where I load an html file through an ajax call following this structure:

PHP - renders -> HTML - javascript appends -> HTML 2nd file

What I would like to do is to get the mustache parameters into the HTML 2nd file, as some data is generated in the initial PHP file and I wouldn't like to make another call to retrieve this data again.

  • Do I need mustache js version for this ?
  • How can I get the data from the PHP in js by using mustache?
  • And how can I get the PHP rendered variables in the HTML 2nd file ?

What I can do is to insert hidden inputs to get the data from them in javascript but I would really like to avoid this practice. I don't like this practice as user can easily modify the inputs.

Any idea??

Was it helpful?

Solution

At the end I found a solution for this. Print the output of a php file on an ajax call.

Mustache_Autoloader::register();
$m = new Mustache_Engine(array(
     'loader' => new Mustache_Loader_FilesystemLoader('./templates/')
));
echo $m->render('templatename', $o);

and then using .html(data); with jQuery

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top