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

(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
Reply
#22

(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]
Reply
#23

[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]
Reply
#24

(This post was last modified: 08-23-2023, 07:45 AM by foxbille.)

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.
Reply
#25

You paste code helper('form') in controller?
Reply
#26

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
Reply
#27

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

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

nope Sad
Reply
#29

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

(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']; 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB