Search code examples
javascripthtmlgrailsgroovyunderscore.js-templating

Importing an HTML template in Grails


I'd like to pull in a static HTML file that I'll use as an Underscore template in my front-end JavaScript. I've tried the following with no luck:

<link rel="import" href="${resource(plugin: 'my-app-name', dir: 'tpl', file: 'foo.html')}"/>
<g:external dir="tpl" file="foo.html" type="html" />

The file sits at web-app/tpl/foo.html.

The ultimate goal is to use the new HTML import syntax to access the file's contents via JavaScript.


Solution

  • The following worked for me, though I'm not sure if it's the best solution: In UrMappings.groovy: static excludes = ['tpl/foo.html']. This made the link tag work in page.gsp <link rel="import" href="${resource(plugin: 'my-app-name', dir: 'tpl', file: 'foo.html')}"/>.