Why can't I pass this variable to a Twig view? |
I am working on a online newspaper/blogging application with CodeIgniter 3.1.8 and Bootstrap 4. I have decided to add themes to it. The application is not HMVC, only MVC.
The themes directory is outside application as can be see in the image below: ![]() Inside themes I have the theme directory (of course) which contains the "master view", Code: layout.php ![]() How I use the theme views In application/core I have added a MY_Loader.php file with the following contents: Code: <?php defined('BASEPATH') OR exit('No direct script access allowed'); In my Posts controller's index() method, I load the view passing it the data: Code: public function index() { Using Twig for the themes The next step was to add the [i]Twig[/i] template engine to the theme(s). For this purpose, I use CodeIgniter Simple and Secure Twig. I have:
Code: private $config = [ 'paths' => [FCPATH . '/themes', VIEWPATH], 'cache' => '/path/to/twig/cache', ]; The problem According to the docs of CodeIgniter Simple and Secure Twig, we can set a global variable like so: Code: $this->twig->addGlobal('sitename', 'My Awesome Site'); So, I added Code: $this->twig->addGlobal('siteTitle', 'My Awesome Site'); in the Posts controller: Code: public function index() { Yet, in themes\caminar\layout.php the line Code: <title>{{siteTitle}}</title> does not display "My Awesome Site" inside the <title> tag. What am I doing wrong? |
Messages In This Thread |
Why can't I pass this variable to a Twig view? - by Ajax30 - 10-30-2020, 04:26 AM
RE: Why can't I pass this variable to a Twig view? - by InsiteFX - 10-30-2020, 02:15 PM
|