We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Simple example using Volt not working

Hello,

I am learning Volt using this toturial, so I just created a very basic view in app/views/posts/index.phtml like so:

<!DOCTYPE html>
<html>
    <head>
        <title>{{ title }} - An example blog</title>
    </head>
    <body>
        <h1>{{ title }}</h1>

    </body>
</html>

And the corresponding controller in app/controllers/PostsController.php

<?php

use Phalcon\Mvc\Controller;

class PostsController extends Controller
{
    public function indexAction()
    {

        $this->view->title = "Hello";

    }

}

But when I access to locahost/myapp/posts, I get this output:

{{ title }}

But I expected "Hello" to be displayed instead. I suspected that Volt was not initiated in the bootstrap file so I added this code to the view component setup:

    $view->registerEngines(
        [
            '.volt' => 'voltService',
        ]
    );

But now I get the following error:

Exception: Service 'voltService' wasn't found in the dependency injection container

Do you have any idea hwo to solve this issue ?

Thanks a lot



1.5k

Hello, thank you for your help but I would like to understand what is the simpliest way to integrate Volt in a phalcon application ? (the documentation is not clear for me, I really don't get it)

Hi @aurelSon is easy. You must config a volt service

Basically config volt service and then set .phtml file extension to volt

Good luck



1.5k

Hi, actually I just changed .phtml to .volt and it works ! thanks

Hi @aurelSon is easy. You must config a volt service

Basically config volt service and then set .phtml file extension to volt

Good luck