Vue like components in PHP/Codeigniter 4 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: Vue like components in PHP/Codeigniter 4 (/showthread.php?tid=77779) |
Vue like components in PHP/Codeigniter 4 - andersdn11 - 10-17-2020 Hi All, Starting up a new CI4 project just coming out of a Vue and wordpress site, in vue i can use components in wordpress i can use blocks that gets passed in user fields which i can react too in my frontend. I think it would be nice if i could create the same kind of reuseable components in CI4. Imagine i have a view file that displays an image + text block. Would it be possible to pass params to the view file i can then catch in the corresponding file, Ideally it would look like this : PHP Code: // About page RE: Vue like components in PHP/Codeigniter 4 - includebeer - 10-18-2020 You can already do that: https://codeigniter4.github.io/userguide/outgoing/views.html#adding-dynamic-data-to-the-view But you need to use PHP syntax, not JavasScript like you did in your example: PHP Code: <?php echo view('component/img_text', ['flip' => true]); ?> Then in img_text.php you can use the variable $flip and in text.php you can use $bg and $columns. RE: Vue like components in PHP/Codeigniter 4 - andersdn11 - 10-18-2020 perfect! The view layout and sections seems like a good option for what Vue calls "slots", might have to dive deeper into that. |