View Component |
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
Learning Codeigniter
10-22-2022, 09:32 AM
(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') ?>
@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
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.
I think this would be really helpful to you: Components library for CI4. It allows to encapsulate html and css classes/styles into reusable website building blocks.
See it here: https://packagist.org/packages/dgvirtual...components It allows to write this in your view: PHP Code: <x-green-button onclick="alert('I was clicked!')"> PHP Code: <button Bonfire2 was written mainly by Lonnie Ezell (@kilishan), so most of the credit goes to him. Hope you will find it as useful as I have.
==
Donatas G. |
Welcome Guest, Not a member yet? Register Sign In |