我正在尝试将src文件夹中存储的css链接到也存储在src中的树枝。通常,您可以使用以下方式链接样式表:
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
有没有一种方法可以执行相同的操作,但是可以使用src / folder / css中存储的文件?
src / Data / Templates / Template / index.html.twig
{% block templateCss %}
<style>
{{ FileManager.getCss('Data/Templates/Template/assets/css/index.css') }}
</style>
{% endblock %}
src / Service / FileManagerService.php
public function getCss($path) { $css = ''; $filePath = substr($path, 0, strrpos( $path, '/')); $fileName = substr($path, strrpos( $path, '/') + 1); $finder = new Finder(); $finder->name($fileName)->files()->in($this->container->get('kernel')->getRootDir().'/'.$filePath); foreach ($finder as $file) { $css .= file_get_contents($file); } return $css; }