PHP code example of liip / frctl-twig

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

    

liip / frctl-twig example snippets


  "autoload": {
    "psr-4": {
      "Frctl\\": "php-twig/"
    }
  }


class TwigFilesystemLoader extends BaseTwigFilesystemLoader
{
    /**
     * Should probably be set via a setter from configuration
     *
     * @var string
     */
    private $fractalPath = '/path/to/fractal/twig/templates';

    /**
     * @param string $name
     *
     * @return string
     */
    protected function findTemplate($name)
    {
        $fractalPath = $this->getFractalPath();
        if ($fractalPath && preg_match('/^@fractal-(.*)$/', $name, $templatePath)) {
            $fullFilePath = $fractalPath . '/' . $templatePath[1];

            return $fullFilePath;
        }

        ...
    }
}

    if (class_exists('Frctl\TwigExtensions')) {
        $extensions = \Frctl\TwigExtensions::getExtensions();
        foreach ($extensions as $extension) {
            $twig->addExtension($extension);
        }
    }