[英]Silex: Separate javascript and twig template
I would use an external javascript file to use it into my twig template. 我会使用一个外部javascript文件将其用于我的树枝模板。
I hade read here that I should install asset so this is how I have done: 我在这里读过我应该安装资产,所以这是我做的事情:
accueil.twig 树枝
{{ app.request.basepath }}.javascript.js
<!Doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Créer un utilisateur</title>
<style>
#plateforme{
width:1200px;
height:600px;
border-style:solid;
border-color:blue;
background-color:white;
}
</style>
<body>
{{ asset('javascript.js') }}
<div id="plateforme" onclick="Changecolor()"></div>
</body>
But javascript code doesn't work, only if I put all code into twig template. 但是,仅当我将所有代码放入树枝模板中时,JavaScript代码才起作用。
I'm using Silex framework. 我正在使用Silex框架。
现在它可以工作了,不需要任何资产,只需
<script src="templates/javascript.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.