Welcome Guest, Not a member yet? Register   Sign In
Twig integration in CI4
#11

See https://github.com/kenjis/codeigniter-ss-twig
Reply
#12

hi @kenjis

Thank you so much.
Reply
#13

(This post was last modified: 04-07-2023, 09:22 AM by foxbille.)

(03-20-2023, 01:10 AM)kenjis Wrote: See https://github.com/kenjis/codeigniter-ss-twig

Hello,
Can you please give an exemple using base_url() in a twig template
like we do in a basic codeigniter view
href="<?= base_url('admin/settings') ?>"

All i found was , in controller
$this->twig->addGlobal('base_url', base_url() );
in template
href="{{ base_url }}/admin/settings"
Thanks
Reply
#14

Code:
href="{{ base_url('admin/settings') }}"
Reply
#15

(04-07-2023, 06:37 PM)kenjis Wrote:
Code:
href="{{ base_url('admin/settings') }}"

Ok, thanks!

And how do i get rid of

<!-- DEBUG-VIEW START [...]

Coming from codeigniter/View/view.php

Eric
Reply
#16

(This post was last modified: 04-08-2023, 05:00 PM by kenjis.)

I think if you use Twig, the debug comments will not be added.
And these are not added in production environment.

If you don't need them in development environment.
PHP Code:
view('foo/bar'$data, ['debug' => false]); 
Reply
#17

(04-08-2023, 04:59 PM)kenjis Wrote: I think if you use Twig, the debug comments will not be added.
And these are not added in production environment.

If you don't need them in development environment.
PHP Code:
view('foo/bar'$data, ['debug' => false]); 

I use twig and debug comments are displayed!
To render view, i use $this->twig->render
PHP Code:
return $this->twig->render('bookmark/index',$data, ['debug' => false]); 
does not change a thing
And what about pagination ?
code of app\Views\Pager\pagination.twig is diplayed between <!-- DEBUG-VIEW START ... and <!-- DEBUG-VIEW ENDED
Reply
#18

1. The DEBUG-VIEW comment like "<!-- DEBUG-VIEW START 1 APPPATH/Views/Pager/default_full.php -->" is output by CI4's View class.
2. If you use Pagination in CI4 with Twig, the DEBUG-VIEW comment will be output in the output HTML.
3. To disable it, set the CI_DEBUG constant to false.
Reply
#19

(04-12-2023, 05:26 AM)kenjis Wrote: 1. The DEBUG-VIEW comment like "<!-- DEBUG-VIEW START 1 APPPATH/Views/Pager/default_full.php -->" is output by CI4's View class.
2. If you use Pagination in CI4 with Twig, the DEBUG-VIEW comment will be output in the output HTML.
3. To disable it, set the CI_DEBUG constant to false.

Ok, thanks for the explanation, that's what i had found using {{ dump(pager.links) }} to understand

But i can't fix it!

I put CI_DEBUG = false in .ENV but it does not work for twig
Even for classic codeigniter view mode (this below is part of the html flow) :
Code:
<!-- DEBUG-VIEW START 1 APPPATH/Views/pagers/default_full.php -->
Only CI_ENVIRONMENT = development can remove "DEBUG-VIEW"

But then, using twig, the flow is still not good, code of default_full.twig is displayed as if htmlentities() was used
Code:
[..]
</div>
{% pager.setSurroundCount(2) %}

&lt;div class=&quot;linklist-paging&quot;&gt;
    &lt;div class=&quot;paging pure-g&quot;&gt;
        &lt;div class=&quot;linklist-pages pure-u-1-3&quot;&gt;
[..]
This is my code :
In app\Config\Pager.php
PHP Code:
public array $templates = [
        'default_full'  => 'App\Views\pagers\default_full.twig'
in app\Controller\Bookmark.php
PHP Code:
public function initController(
    \CodeIgniter\HTTP\RequestInterface $request,
    \CodeIgniter\HTTP\ResponseInterface $response,
    \Psr\Log\LoggerInterface $logger
) {
    parent::initController($request$response$logger);
    $this->bookmarkModel = new bookmarkModel();
    $this->tagModel = new tagModel();
    $this->twig = new \Kenjis\CI4Twig\Twig(['functions' => ['dateSlash','pager'],]);
}
public 
funtion index()
{
$conf = new \Config\Pager();
$pager = \Config\Services::pager();        
$bookmarks 
$this->bookmarkModel->findAll();
$tags $this->tagModel->findAll();
$data = [
    'bookmarks' => $bookmarks
    'tags' => $tags,
    'pager' => $this->bookmarkModel->pager,
];
return 
$this->twig->render('bookmark/index',$data);

in Views\Bookmark\index.twig
PHP Code:
{% extends "default.twig" %}

{% 
block content %}

{% if 
pager is defined %} 
{{ 
pager.links }}
{% endif %} 
in app\Views\default.twig
PHP Code:
<main id="content" class="container" role="main">
    {{ include('menu.twig') }}
    {{ include('header.twig') }}
    {% block content %}{% endblock %}
    {{ include('footer.twig') }}
</
main
Reply
#20

(04-14-2023, 02:43 AM)foxbille Wrote: I put CI_DEBUG = false in .ENV but it does not work for twig
Even for classic codeigniter view mode (this below is part of the html flow) :
Code:
<!-- DEBUG-VIEW START 1 APPPATH/Views/pagers/default_full.php -->

The CI_DEBUG is a PHP constant, not an environment variable.
Yes, to set CI_ENVIRONMENT to production makes it false.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB