문제

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)

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top