I can not understand how to use the template. TWIG.JS and TWIG on views. Here is the controller it is looking for templates:

connect controller via script

public function index() { $views = config('view.paths') ; foreach ($views as $view_path) { $templates = new \FilesystemIterator($view_path . "/shared/",\FilesystemIterator::SKIP_DOTS ); foreach ($templates as $template) { $templateComment = [ "comment" => file_get_contents($template) ]; return 'var twig_templates = '.json_encode($templateComment); } } } 

Next JS:

 var body = $('textarea[name=body]').val(); var _token = $('input[name=_token]').val(); var article_id = $('input[name=article_id]').val(); var user_id = $('input[name=user_id]').val(); var user_name = $('input[name=user_name]').val(); var path = 'http://simpleblog/'; var comment_template = twig({ data: twig_templates['comment'] }); $.ajax({ type: "POST", url : path+'new-comment', data: {body:body,_token:_token, article_id: article_id, user_id: user_id,user_name:user_name}, success : function(data){ var result = comment_template.render(data); } },"json"); var body = $('textarea[name=body]').val(""); document.body.innerHTML = result; 

How to use data from json, insert into template and in view? Examples please, I can not find anything like that, I really have no experience with JS.

View: http://pastie.org/10346899

    0