thecodeholic / php-mvc-framework

PHP MVC Framework
https://www.youtube.com/playlist?list=PLLQuc_7jk__Uk_QnJMPndbdKECcTEwTA1
470 stars 177 forks source link

How to render js files in views #28

Open mahmoudIsProgramer opened 2 years ago

mahmoudIsProgramer commented 2 years ago

Hello thecodeholic , thanks a lot for the the great course and the lovely educational materials . in layouts/main.php there exist {{content}} and as i understood it's to replace the content of view , how can i make similar to this but for js files , i want to load js file in my view without putting it in layouts/main.php beofr tag

thecodeholic commented 1 year ago

That is not straight forward and directly possible at the moment. One Simple solution will be

  1. to extend Application class
  2. Use the new Application class into public/index.php
  3. Add $js and $css arrays into extended class
  4. From controllers's method put your JavaScript or CSS files into new Application class $js and $css
  5. Iterate over them into layout/main.php and render them.

@mahmoudIsProgramer Let me know if this helps.