mdl*_*don 6 grails resources asset-pipeline
我正在尝试使用asset-pipeline插件(v1.0.4)在grails v2.3.1中设置SiteMesh布局,但我不确定如何处理在我的模板的特定位置包含javascript资源(如如果使用资源插件,你会使用r:layoutResources ).
示例布局(grails-app/views/layouts/test.gsp):
<html>
<head>
<title><g:layoutTitle/></title>
<g:layoutHead/>
</head>
<body>
<div class="thecontent">
<g:layoutBody/>
</div>
<asset:javascript src="application.js"/>
<!-- WANT DECORATED PAGE RESOURCES TO BE INCLUDED HERE -->
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
示例gsp(grails-app/views/test.gsp):
<html>
<head>
<meta name="layout" content="test"/>
<title>The Title</title>
<asset:stylesheet src="thispageonly.css"/>
</head>
<body>
<div id="helloworld">
Hello World
</div>
<asset:javascript src="thispageonly.js"/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
生成的装饰页面(忽略资产管道捆绑/等)适用于样式表(因为它在头部)但是javascript失败:
<html>
<head>
<meta name="layout" content="test"/>
<title>The Title</title>
<link rel="stylesheet" href="/assets/thispageonly.css?compile=false"/>
</head>
<body>
<div class="thecontent">
<div id="helloworld">
Hello World
</div>
<!-- *** NOT WHERE I WANT THIS *** -->
<script src="/assets/thispageonly.js?compile=false" type="text/javascript"></script>
</div>
<script src="/assets/application.js?compile=false" type="text/javascript"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
目前我可以使用它的唯一方法是使用g:applyLayout和g:pageProperty:
<!-- grails-app/views/layouts/test2.gsp -->
<html>
<head>
<title><g:layoutTitle/></title>
<g:layoutHead/>
</head>
<body>
<div class="thecontent">
<g:layoutBody/>
</div>
<asset:javascript src="application.js"/>
<g:pageProperty name="page.javascript"/>
</body>
</html>
<!-- grails-app/views/test2.gsp -->
<g:applyLayout name="test2">
<html>
<head>
<title>The Title</title>
<asset:stylesheet src="thispageonly.css"/>
</head>
<body>
<div id="helloworld">
Hello World
</div>
<content tag="javascript">
<asset:javascript src="thispageonly.js"/>
</content>
</body>
</html>
</g:applyLayout>
Run Code Online (Sandbox Code Playgroud)
但是这种偏离meta标签似乎过于复杂(而且我不清楚在未来的升级中是否会支持记录不佳的g:pageProperty).这样做的最佳长期方式是什么?
使用 sitemesh 来控制对象放置是完全有效的用例。Sitemesh 不会去任何地方,我实际上用它来控制子容器和布局继承。在资产管道插件中复制这种内置的流量控制是没有意义的。
另一个非常有用的技巧是使用<g:layoutHead/>
和<g:layoutBody/>
标签,它们也非常有用。
如果这被证明是一个问题,将来我们可能会考虑提供具有此行为的模式。让我知道 asset-pipeline 的进展情况,如果出现此类问题,请随时在 github 上开具票证。显然,我还需要关注堆栈溢出:)
归档时间: |
|
查看次数: |
4786 次 |
最近记录: |