简体   繁体   English

将JavaScript代码存储在Velocity VM模板文件中并包含在页面中

[英]Store javascript codes in velocity vm template file and included in the page

I have javascript code that uses velocity context and rundata objects, I have to have it to be included in a VM template. 我有使用速度上下文和rundata对象的javascript代码,必须将其包含在VM模板中。 Is there a way for me to separate it into standalone file, say, screen-js.vm, and included in the GlobalMacros.vm file, like: 我是否可以将其分为独立文件,例如screen-js.vm,并包含在GlobalMacros.vm文件中,例如:

and screen-js.vm looks like: 和screen-js.vm看起来像:

    $data.setLayoutTemplate("/NoNavigationJs.vm") ##this for not creating any header

    <script type="text/javascript">
    $(document).ready(function() {
         //javascript code ...

    }
</script>

But this doesn't work, here is the page source, with 2 empty lines in the begining: 但这是行不通的,这是页面源代码,开头有2个空行:

<script type="text/javascript">

$(document).ready(function() {
...
}
</script>

What I did wrong here? 我在这里做错了什么? Thanks! 谢谢!

David 大卫

我知道了:#parse(“ path / to / vm file”)可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM