PHP code example of justmd5 / yaf-twig-adapter

1. Go to this page and download the library: Download justmd5/yaf-twig-adapter 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/ */

    

justmd5 / yaf-twig-adapter example snippets




use \Yaf\Bootstrap_Abstract;
use \Yaf\Dispatcher;
use \Yaf\Application;
use \JustMd5\TwigAdapter;

class Bootstrap extends Bootstrap_Abstract
{

	/**
	 * @param Dispatcher $dispatcher
	 */
	protected function _initTwig(Dispatcher $dispatcher)
	{
		$config = Application::app()->getConfig();
		$dispatcher->setView(new Twig(APP_PATH.'views', $config->twig->toArray()));
	}
}



use \Yaf\Bootstrap_Abstract;
use \Yaf\Dispatcher;
use \Yaf\Application;
use \JustMd5\TwigAdapter;

class Bootstrap extends Bootstrap_Abstract
{

	/**
	 * @param Dispatcher $dispatcher
	 */
	  public function _initTwig(Dispatcher $dispatcher)
        {
            if (REQUEST_METHOD !== 'CLI') {
                $config = Application::app()->getConfig();
                $modules_names = explode(',', $config->application->modules);
                $paths = [ROOT_PATH . '/' . APP_NAME . '/views'];
                array_walk($modules_names, function ($v) use (&$paths) {
                    if (is_dir(ROOT_PATH . '/' . APP_NAME . '/modules/' . $v . '/views')) {
                        array_push($paths, ROOT_PATH . '/' . APP_NAME . '/modules/' . $v . '/views');
                    }
                });
                $dispatcher->setView(new Twig($paths, isset($config->twig) ? $config->twig->toArray() : []));
            }

        }
}



ini
[product]

;app
application.view.ext = twig

;twig
twig.cache = APP_PATH "../cache"

[devel : product]

;twig
twig.debug = true
ini
[product]

;app
;此处填写你的modules,多modules","隔开
application.modules = "Index,Log,Demo"
application.view.ext = twig

;twig
twig.cache = APP_PATH "../cache"
[devel : product]
;twig
twig.debug = true