CodeIgniter Forums
Twig integration in CI4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: External Resources (https://forum.codeigniter.com/forumdisplay.php?fid=7)
+--- Forum: Addins (https://forum.codeigniter.com/forumdisplay.php?fid=13)
+--- Thread: Twig integration in CI4 (/showthread.php?tid=76656)

Pages: 1 2 3 4


RE: Twig integration in CI4 - kenjis - 04-14-2023

(04-14-2023, 02:43 AM)foxbille Wrote: But then, using twig, the flow is still not good, code of default_full.twig is displayed as if htmlentities() was used

Try raw:
https://twig.symfony.com/doc/3.x/filters/raw.html


RE: Twig integration in CI4 - foxbille - 04-17-2023

(04-14-2023, 03:26 AM)kenjis Wrote:
(04-14-2023, 02:43 AM)foxbille Wrote: But then, using twig, the flow is still not good, code of default_full.twig is displayed as if htmlentities() was used

Try raw:
https://twig.symfony.com/doc/3.x/filters/raw.html

Hi,
Thanks, but doesn't work either.
[code]
</form>
</div>



{% pager.setSurroundCount(2) %}

<div class="linklist-paging">
<div class="paging pure-g">
<div class="linklist-pages pure-u-1-3">
{% if pager.hasPrevious() %}

<a href="{{pager.getFirst()}}" aria-label="{{ lang('Pager.first') }}">
<span aria-hidden="true"> <i class="fa fa-angle-double-left px-2"></i></span>
[/php]


RE: Twig integration in CI4 - filipussetio - 04-27-2023

[quote pid="407923" dateline="1679299816"]
Hi @kenjis

So i've integrated my Twig on CI4 with your Twig but i got this error.

Unknown "form_error" function.

did i miss something on the installation or do i have to modify something to use form_error function?

Thanks!


[/quote]


RE: Twig integration in CI4 - foxbille - 08-23-2023

Hi All,
Have the same problem :
an Add form worked well until i add
PHP Code:
{{ form_error('lastname') }} 

Twig\Error\SyntaxError

Unknown "form_error" function.


RE: Twig integration in CI4 - ozornick - 08-23-2023

You paste code helper('form') in controller?


RE: Twig integration in CI4 - foxbille - 08-23-2023

Thanks for replay
I might not have understand your question
anyway, here is my code
In controller

PHP Code:
use \Kenjis\CI4Twig\Twig;
class 
Trace extends BaseController
{
    protected $twig;

    public function initController(
        \CodeIgniter\HTTP\RequestInterface $request,
        \CodeIgniter\HTTP\ResponseInterface $response,
        \Psr\Log\LoggerInterface $logger
    
) {
        parent::initController($request$response$logger);
        $this->traceModel = new TraceModel();
        $this->twig = new Twig(['functions' => ['dateSlash']]);
    }    
[...]
    public function add()
    {
        $validation =  \Config\Services::validation();
        if ($this->request->getMethod() === 'post') {
            if ($this->validate('traceRules')) {
            [...]
                $this->session->setFlashdata('success''trace modifiée');
                return redirect()->to('/trace/index');
            } else {
                return redirect()->back()->withInput();
            }
        } else {
            $trace = new \App\Entities\trace();
        }
        return $this->twig->render('trace/add', [
            'validation' => $validation,
            'trace' => $trace,
            'url' => base_url('/trace/add'),
            'titre' => 'Ajouter',
        ]);
    
in view

PHP Code:
{% extends "default.twig" %}

{% 
block content %}
<
form name="trace" method="post" action="{{ url }}">

  <div class="field">
    <label class="label">Nom</label>
    <div class="control">
      <input class="input" type="text" name="lastname" value="{{ trace.lastname }}">
    </div>
    {{ form_error('lastname') }}
  </div



RE: Twig integration in CI4 - ozornick - 08-23-2023

Fixed?
public function add()
{
helper('form');
....
}


RE: Twig integration in CI4 - foxbille - 08-24-2023

(08-23-2023, 09:56 AM)ozornick Wrote: Fixed?
    public function add()
    {
        helper('form');
        ....
    }

nope Sad


RE: Twig integration in CI4 - kenjis - 08-24-2023

Try to load the helper before `$this->twig = new Twig(['functions' => ['dateSlash']]);`


RE: Twig integration in CI4 - foxbille - 09-02-2023

(08-24-2023, 05:05 PM)kenjis Wrote: Try to load the helper before `$this->twig = new Twig(['functions' => ['dateSlash']]);`

Does not fix.
but I might say that helper is yet loaded in baseController.php
PHP Code:
protected $helpers = ['form''date''iti'];