I want to implement a pretty basic rjs kind utility in php. For those who have no prior knowledge of it, the rjs utility in Ruby on Rails returns application\javascript
content-type for ajax requests. This is pretty handy when we want to change the inner html of two different divs through ajax in one request.
So what I need is to read html stream of some *.tpl.php file so that from the server side code, I can return javascript strings as:
$rjsStr = "$('#div1').html(".Util::getHtmlFromTpl($outputParams1, 'tplfile1.tpl.php').");";
$rjsStr .= "$('#div2').html(".Util::getHtmlFromTpl($outputParams2, 'tplfile2.tpl.php').");";
return $rjsStr;
Now my ajax request would look like $.ajax({url:'/controller/action.php?param1=1¶m2=2',success:function(result){eval(result);}})
Edit The problem is that I don't know how to get the html stream of php file. I simply tried include('path_to_file/tplfile1.tpl.php');
but that doesn't return the html stream as a variable.
PS: I don't want to use file_get_contents
for the security reasons.