简体   繁体   English

如何在Grails中呈现包含HTML中包含源文件的HTML文件?

[英]How do i render a html file in grails that has source files included in the html?

I have a project in grails where I'm doing the UI part in a separate grails independent project. 我在grails中有一个项目,我在一个单独的grails独立项目中做UI部分。 I'm calling the html file in the UI project from the grails controller in a different project. 我正在从另一个项目的grails控制器中调用UI项目中的html文件。

How do I render the html files from the controller? 如何从控制器渲染html文件? Currently, I'm using the render command to convert the htmlContent into text format and rendering the text. 当前,我正在使用render命令将htmlContent转换为文本格式并呈现文本。 But I released I cant include relative source tags inside that html and I'll need to hardcode it in the html. 但是我发布了我无法在该html中包含相对源标签,并且需要在html中对其进行硬编码。

render text: htmlContent, contentType:"text/html", encoding:"UTF-8"

Any other effective way to render the html (from a different project) from the grails controller? 还有其他有效的方法可以从grails控制器呈现html(来自其他项目)吗?

The following is the problem as I understand it: 据我了解,以下是问题:

  1. You have a Grails project containing a controller. 您有一个包含控制器的Grails项目。
  2. You have Grails plugin project containing the UI (html, css, etc). 您具有包含UI(html,css等)的Grails插件项目。
  3. The controller project is configured in grails-app/conf/Build.groovy to depend on the UI plugin. 在grails-app / conf / Build.groovy中将控制器项目配置为依赖于UI插件。
  4. You want to render the UI in the UI plugin project from the controller in the controller project. 要呈现在从控制器项目控制器中的UI插件项目的UI。

Views are rendered exactly the same way regardless of whether they are contained in the same project or not. 无论视图是否包含在同一项目中,视图的呈现方式都完全相同。 For example, if the UI project has a view at grails-app/views/ui/index.gsp , then the controller in the controller project can render it like this: 例如,如果UI项目的视图位于grails-app / views / ui / index.gsp ,则控制器项目中的控制器可以如下所示呈现它:

render(view: '/ui/index')

I don't know where your htmlContent is coming from, but usually rendering text is for very simple things, such as JSON; 我不知道您的htmlContent来自何处,但是渲染文本通常是用于非常简单的事情,例如JSON; not for HTML which may contain other resources (like images and CSS files). 不适用于可能包含其他资源(例如图像和CSS文件)的HTML。

See, in Grails the URLs to static resources , such as images and CSS files, are generated by either the Resources or Asset-Pipeline plugins. 在Grails中,请参阅由资源或Asset-Pipeline插件生成的指向静态资源 (如图像和CSS文件)的URL。 Either way, trying to set the path to such resources directly in HTML code will not work. 无论哪种方式,尝试直接在HTML代码中设置此类资源的路径都行不通。

If you convert you htmlContent into a GSP page and use either the Resources or Asset-Pipeline, then you'll be able to render HTML content with sources. 如果您将htmlContent转换为GSP页面并使用“资源”或“资产管道”,则可以使用源呈现HTML内容。

Check grails-app/conf/Build.groovy for the line compile ":asset-pipeline:xxx" in the plugins section. 检查grails-app / conf / Build.groovy中的插件”部分中的行编译“:asset-pipeline:xxx” If it's there, heck just go with the Asset-Pipeline ! 如果在那里,那么就跟Asset-Pipeline一起去吧! It's the new way to manage static resources. 这是管理静态资源的新方法。

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

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