Welcome Guest, Not a member yet? Register   Sign In
Anyone using HTMX with CI?
#1

Hi, I've recently discovered and am having fun with https://htmx.org/

I was wondering if anyone has used it in their CI projects and if so, have you organised your code in any particular way?

Thanks.
Reply
#2

A powerful package for use in Codeigniter has been published by one of the members of Codeigniter.

https://github.com/michalsn/codeigniter-htmx
Reply
#3

(This post was last modified: 02-22-2023, 03:31 PM by n2fole00.)

(02-22-2023, 11:54 AM)datamweb Wrote: A powerful package for use in Codeigniter has been published by one of the members of Codeigniter.

https://github.com/michalsn/codeigniter-htmx

Cool, I set up a test and tried an example from the docs, but I got this exception when accessing http://localhost/ci4/test/public/ which takes you to Home::index

Code:
"Call to undefined method Michalsn\CodeIgniterHtmx\View\View::fragmentEnd()"

PHP Code:
<h1>Welcome to CodeIgniter <?= CodeIgniter\CodeIgniter::CI_VERSION ?></h1>
            <?php $this->fragment('example'); ?>
            <h2><?= $caption?></h2>
            <?php $this->fragmentEnd(); ?>

PHP Code:
class Home extends BaseController
{
    public function 
index()
    {
        try {
            return 
view('welcome_message', ['caption' => 'Full page returned']);
        } catch (\
Exception $e) {
            exit(
$e->getMessage());
        }
    }

    public function 
pageFragment(): string
    
{
        return 
view_fragment('welcome_message''example', ['caption' => 'Only page fragment returned']);
    } 

Any idea why that is?

Setup was

Code:
composer require michalsn/codeigniter-htmx
Reply
#4

Try this demo first https://github.com/michalsn/codeigniter-htmx-demo
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#5

Hi,
this documention is wrong : https://michalsn.github.io/codeigniter-h...fragments/

Actual "fragmentEnd" function is : 
PHP Code:
$this->endFragment(); 

Github Source for this function

I've submitted an issue on @michalsn repo.
Reply
#6

(This post was last modified: 03-16-2023, 01:19 AM by SubrataJ.)

tell me how do I push extra cdn link to the header and footer using htmx. cause I don't wanna load all the assets on the first load. this is where I got stuck.
Learning Codeigniter 
Reply
#7

In general, it's always a good practice to structure your code in a way that promotes modularity, maintainability, and reusability. For instance, you may want to consider separating your HTML, JavaScript, and CSS code into separate files and folders, or use a modular architecture like MVC (Model-View-Controller) or MVVM (Model-View-ViewModel) to organize your code.

You may also want to consider using a build tool like Webpack or Gulp to automate tasks like code minification, bundling, and transpiling. This can help optimize your code and improve the performance of your application.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB