Symfony 获取 twig 模板的文件路径,该文件在 customBundle:Resources:views 中而不是在 web 目录中

Symfony Get a file path into a twig template, the file is in customBundle:Resources:views not in web dir

在我的一个树枝模板中,我有一个 javascript 块 我必须在其中给出某个 html 文件的路径。 我试过这个但是有控制台错误

jQuery(document).ready(function ($) {
$("#content").builder({
themeFile: '{{ "ContentbuildBundle:Template:theme.html.twig" }}',
toolbar: 'right',
onRender: function() {
$('#contentarea').trigger('focusout');
}
});
}


enter image description here

使用 twig 时,您可以 link 使用 asset twig 函数 Twig Docs

中所述的资产

不幸的是,我认为这个功能只适用于link到public个文件,即位于web目录的文件。

此外,您可以使用 include 函数呈现 HTML 的内容。

你能具体说明你需要达到什么目的吗? 请记住,无法访问 public 目录之外的文件。

编辑: 如果你需要渲染一些 HTML,你应该把它放在 resouces 目录(私有)上并使用 twig 包含它。