PHP code example of cloudbase / latte-helper

1. Go to this page and download the library: Download cloudbase/latte-helper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cloudbase / latte-helper example snippets


class IndexController extends AbstractLatteController
{
    #[Route('/', name: 'app_index')]
    public function index(): Response
    {
        return $this->renderTemplate('index.latte', [
            'appName' => 'Test',
        ]);
    }
}

class BaseAppController extends AbstractLatteController
{
    // Path relative to your project root
    protected string $templateDir = '/templates/frontend';
}

class AppIndexController extends BaseAppController
{
    #[Route('/', name: 'app_index')]
    public function index(): Response
    {
        // You can omit the .latte suffix if desired
        return $this->renderTemplate('index');
    }
}

class IndexController extends AbstractLatteController
{
    #[Route('/', name: 'app_index')]
    public function index(): Response
    {
        $welcomeText = sprintf(
            'Welcome to %s!',
            $this->getApp()->getEnvironmentOption('app_name') ?? 'Your App'
        );
        
        return $this->renderTemplate('index', [
            'text' => $welcomeText,
        ]);
    }
}


class BaseAppController extends AbstractLatteController
{
    protected string $templateDir = '/templates/frontend';
    
    protected function globalData(): array
    {
        return array_merge(
            parent::globalData(), // Keeps the $app variable
            [
                'myGlobal' => true,
            ]
        );
    }
}



return [
    App\Classes\MyCustomExtension::class => [],
];