Skip to content

Instantly share code, notes, and snippets.

@fiedsch

fiedsch/tl_templates.php

Last active Feb 27, 2020
Embed
What would you like to do?
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