Last active
February 27, 2020 10:49
-
-
Save fiedsch/584bfe7b69c23b3105a97d2667112086 to your computer and use it in GitHub Desktop.
tl_templates.php experiments (@see https://github.com/contao/contao/issues/1399)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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