Skip to content

Instantly share code, notes, and snippets.

@fiedsch
Last active February 27, 2020 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fiedsch/584bfe7b69c23b3105a97d2667112086 to your computer and use it in GitHub Desktop.
Save fiedsch/584bfe7b69c23b3105a97d2667112086 to your computer and use it in GitHub Desktop.
tl_templates.php experiments (@see https://github.com/contao/contao/issues/1399)
<?php
$GLOBALS['TL_DCA']['tl_templates'] = array
(
// Config
'config' => array
(
'dataContainer' => 'Folder',
'validFileTypes' => 'html5,twig', // add twig
// [...]
public function adjustSettings()
{
Contao\Config::set('uploadPath', 'templates');
Contao\Config::set('editableFiles', 'html5,twig'); // add twig
}
public function addNewTemplate()
{
$arrAllTemplates = array();
/** @var Symfony\Component\Finder\Finder $files */
$files = Contao\System::getContainer()->get('contao.resource_finder')->findIn('templates')->files()->name('/\.html5$/');
// <new code>
// Nur richtig unter der Annahme: "wo es ein Unterverzeichnis contao/ gibt, gibt es auch views/"
// Works on my mashine ;-)
$twigResourcesPaths = array_filter(
array_map(
function($path) { return preg_replace("/contao$/", 'views', $path); },
Contao\System::getContainer()->getParameter('contao.resources_paths')
),
function($path) { return is_dir($path); }
);
/** @var Symfony\Component\Finder\Finder $twigFiles */
$twigFiles = \Symfony\Component\Finder\Finder::create()->in($twigResourcesPaths)->files()->name('/\.twig$/');
$files->append($twigFiles);
// </new code>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment