作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
由于没有以下延迟选项:
<asset:javascript src="custom_view_script.js"/>
<asset:deferredScripts/>
最佳答案
最简单的方法是使用站点网格。
在您的布局中,您需要
<g:pageProperty name="page.script"/>
<content tag="script">
<script type="application/javascript">
... your code here ...
</script>
</content>
class MyContentTagLib implements RequestConstants {
static namespace = "mycontent"
Closure addContent = { Map attrs, body ->
if( body != null ) {
def htmlPage = getPage()
if( htmlPage instanceof GSPSitemeshPage && attrs.tag ) {
def name = attrs.tag
def sitemeshPage = (GSPSitemeshPage) htmlPage
StreamCharBuffer currentContent = sitemeshPage.getContentBuffer( "page.$name" ) as StreamCharBuffer
StreamCharBuffer newContent = wrapContentInBuffer( body )
if( currentContent ) {
newContent.writeTo( currentContent.writer )
newContent = currentContent
}
sitemeshPage.setContentBuffer( name, newContent )
}
}
}
private AbstractHTMLPage getPage() {
return (AbstractHTMLPage)getRequest().getAttribute(PAGE)
}
private StreamCharBuffer wrapContentInBuffer(Object content) {
if (content instanceof Closure) {
content = content()
}
if (!(content instanceof StreamCharBuffer)) {
// the body closure might be a string constant, so wrap it in a StreamCharBuffer in that case
FastStringWriter stringWriter=new FastStringWriter()
stringWriter.print((Object)content)
StreamCharBuffer newbuffer = stringWriter.buffer
newbuffer.setPreferSubChunkWhenWritingToOtherBuffer(true)
return newbuffer
} else {
return (StreamCharBuffer)content
}
}
}
<mycontent:addContent tag="script">
<script type="application/javascript">
... your code here ...
</script>
</mycontent:addContent>
关于grails - 如何使用Grails Asset Pipeline在 View 中声明要在页脚中呈现的JavaScript Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30881156/
我是一名优秀的程序员,十分优秀!