gpt4 book ai didi

javascript - Twig Assets 找不到 js 文件

转载 作者:行者123 更新时间:2023-11-29 19:22:56 25 4
gpt4 key购买 nike

我使用 Symfony 2.7。我试图通过 javascript block 加载 javascript 文件。但 Twig 总是抛出以下错误信息:

An exception has been thrown during the compilation of a template ("Unable to find file "@AppBundle/Resources/public/js/".") in "security/registration.html.twig".

这里是我的 registration.html.twig:

{% block body %}
//divs.
{% endblock %}

{% block javascripts %}
{% javascripts '@AppBundle/Resources/public/js/*' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}

我检查了文件夹路径,没问题,在我看来:/var/www/html/UserAuthentication/app/Resources/public/js/registration.js

这里是 index.twig.html,其中包含 registration.twig.html:

{% extends '::base.html.twig' %}

{% block body %}
<div id="wrapper">
<div id="container">

{{ render(controller('AppBundle:Security:login')) }}

{{ render(controller('AppBundle:Security:register')) }}

</div>
</div>
{% endblock %}

这就是我的 base.twig.html 的样子:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>{% block title %}Welcome!{% endblock %}</title>
{% block stylesheets %}{% endblock %}
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">

</head>
<body>
<div class="container">
{% block body %}{% endblock %}
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
{% block javascripts %}{% endblock %}
</body>
</html>

我希望 registration.js 位于 javascripts block 中

我的config.yml:

assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ 'AppBundle' ]

我已经尝试过这样的 bundles:bundles: [],但它不会改变 twig 中的任何内容,我的 twig 模板仍然抛出相同的异常。

而且我真的没有找到,问题在哪里/我不明白。有人知道我的错误在哪里吗?

这里是我的包依赖项(composer.json):

"require": {
"php": ">=5.3.9",
"symfony/symfony": "2.7.*",
"doctrine/orm": "~2.2,>=2.2.3,<2.5",
"doctrine/dbal": "<2.5",
"doctrine/doctrine-bundle": "~1.4",
"symfony/assetic-bundle": "dev-master",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~4.0",
"sensio/framework-extra-bundle": "~3.0,>=3.0.2",
"incenteev/composer-parameter-handler": "~2.0",
"ircmaxell/password-compat": "~1.0.3"
},

是的,我已经运行了app/console cache:clearapp/console assets:installapp/console assetic:dump命令很多次。 :(

最佳答案

@AppBundle/Resources/public/js/* 指向 src/AppBundle/Resources/public/js/*不要到 app/Resources/public/js/*

要使用您应该使用的应用程序/资源:“%kernel.root_dir%/Resources/assets/js/”

我开始使用 S2.8 并遇到类似的问题(尚未全部解决)。

关于javascript - Twig Assets 找不到 js 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32299792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com