Question

I have a controller and view file, from controller I am setting the data array for view, in the view file I am creating an instance of Mustache.php class and render the template of view.

In the second scenario: from controller I am setting the data array for view, and from view file I am calling Mustache.js to render a template.

Please let me know which is Ideal approach to do the same?

I am using PHP sonic framework(MVC)

Was it helpful?

Solution

Both of them are OK. If you use PHP, you won't deal php-js conversion. Php mustache instance keeps you from conversion.

Note: A note for your MVC usage:

Mustache is logicless template. This means you need to prepare your data structure in controller and pass it to the view. Do not use filtering, conditioning, controlling structures on your view.

OTHER TIPS

I think JS is the best option. Imagine that you need to change DOM using these data variables you passed from your controller in the future. If you have it on JS stack it should be easier than if you have it on PHP stack.

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