Welcome Guest, Not a member yet? Register   Sign In
View Component
#1
Wink 
(This post was last modified: 10-22-2022, 04:52 AM by SubrataJ.)

is there any way we can make a reusable component of a specific part of  HTML and use it throughout the application? 

I have heard rumors that it is possible but I have had a hard time finding an article on the same on the web.

Thank you in Advance, Keep Grinding  Cool
Learning Codeigniter 
Reply
#2

(This post was last modified: 10-22-2022, 09:35 AM by captain-sensible. Edit Reason: forgot to add some points )

if you use the approach of "layout" in your views , then you can create for want of a better word , chunks of html which can be inserted into a single main web page

So in my case my view "layout" contains the header(with links to css , bootstrap etc ) , main middle section where different content is inserted and footer(also containing jquery ) in the middle it has
Code:
<?= $this->renderSection('content') ?>


each different "chunk" of html will be in the form :

Code:
<?= $this->extend('layout') ?>

<?= $this->section('content') ?>
<!-- you can even inject content into chunks of html that will extend tyhe main lay out using line below-->

<?= $this->include('carousel') ?>

<!-- in the above i inject a chunk which uses bootstrap carousel-->


<!-- all html content here-->
<?= $this->endSection() ?>
CMS CI4     I use Arch Linux by the way 

Reply
#3

CI4 has View Cells.
See https://codeigniter4.github.io/CodeIgnit...cells.html
Reply
#4

(This post was last modified: 10-22-2022, 08:26 PM by SubrataJ.)

@captain-sensible thanks for the reply but I am already aware of the rendersection..

Thank you @kenjis for now this looks pretty promising to me after going through the documentation. i will give it a shot
Learning Codeigniter 
Reply
#5

Cells and layouts are both parts of the puzzle. If you don't need any logic with the HTML chunks, you could just store them as a separate view and include them wherever you need them.
Reply
#6

(10-24-2022, 06:52 AM)kilishan Wrote: Cells and layouts are both parts of the puzzle. If  you don't need any logic with the HTML chunks, you could just store them as a separate view and include them wherever you need them.

Thanks for the insights.
Learning Codeigniter 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB