kenjis / codeigniter-ss-twig

A Simple and Secure Twig integration for CodeIgniter 3.x and 4.x
MIT License
168 stars 46 forks source link

unable to add codeigniter function at twig #27

Closed waptik closed 7 years ago

waptik commented 7 years ago

Hi i am using this library but facing a problem while trying to use functions. Question on SO is not mine but i am facing same problem. i have already loaded url and form helpers in my controller. I hope someone can help.

my error

n uncaught Exception was encountered

Type: LogicException

Message: Unable to add function "base_url" as extensions have already been initialized.

http://stackoverflow.com/questions/41662788/unable-to-add-codeigniter-function-at-twig (reffered from SO)

kenjis commented 7 years ago

You don't have to add base_url, because this library does it. See https://github.com/kenjis/codeigniter-ss-twig#supported-codeigniter-helpers.

waptik commented 7 years ago

Okay thanks, I got it working.

Also I have this issue . I added the widget() method your library as follow:

// libraries / Twig.php
.....
public function widget($name){
$this->_widget = '_includes.'$name.'.html';
return $this;
}

// in my controller/home.php
.....
public function index(){
$this->twig->addGlobal->('twig', $this->twig);
......
$this->twig->display('home');
}

// views home.php
{# let's include the header page #}

{% include twig.widget.header %}

{# end #}

............#

This is the error I get A PHP Error was encountered Severity: Warning Message: Missing argument 1 for Twig::widget(), called in .......

kenjis commented 7 years ago

Do you want like this?

public function widget($name){
  return $this->_widget = '_includes.'$name.'.html';
}
{% include twig.widget(header) %}
waptik commented 7 years ago

Yes that's what I was working on. Do you know any idea how to achieve it? UPDATE 1 : I tried your solution but I got this error : An Error Was Encountered

Unable to find template "_includes/0.html" (looked into: /home/waptik/public_html/../..app/views/twig).

I don't know why it's 0.html and not header.html

UPDATE 2: I got it working with this {% include twig.widget('header') %} Thanks for the hand.