Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The trick is to get the framework to parse your javascript, or your CSS, or anything else in the static directories. Here's an easy solution. </p> <p>Add a <code>controllers.StaticParser</code> controller:</p> <pre><code>package controllers; import play.mvc.Controller; public class StaticParser extends Controller { public static void parse(String route) { render("/" + route); } } </code></pre> <p>To your <code>conf/routes</code> file add:</p> <pre><code>GET /parse/{&lt;.*&gt;route} StaticParser.parse </code></pre> <p>The regexp in that route is very important, otherwise you can't add pathing to the request. To request a parsed static resource, such as a js script, use:</p> <pre><code>&lt;script src="/parse/public/javascripts/test.js" language="javascript" type="text/javascript" &gt;&lt;/script&gt; </code></pre> <p>Unfortunately, you can't use the <code>#{script 'test.js' /}</code> format, because the script tag looks for the static file. To correct that irksome-ness, here's a shameless hack of the script tag: the <code>#{parsescript 'test.js'/}</code> tag. It should go to <code>/views/tags/parsescript.tag</code>:</p> <pre><code>{ * insert a parsescript tag in the template. * by convention, referred script must be put under /public/javascripts * src (required) : script filename, without the leading path "/public/javascripts" * id (opt.) : sets script id attribute * charset (opt.) : sets source encoding - defaults to current response encoding * * #{parsescript id:'datepicker' , src:'ui/ui.datepicker.js', charset:'${_response_encoding}' /} }* %{ (_arg ) &amp;&amp; (_src = _arg); if (!_src) { throw new play.exceptions.TagInternalException("src attribute cannot be empty for script tag"); } _src = "/public/javascripts/" + _src try { _abs = play.mvc.Router.reverseWithCheck(_src, play.Play.getVirtualFile(_src), false); } catch (Exception ex) { throw new play.exceptions.TagInternalException("File not found: " + _src); } }% &lt;script type="text/javascript" language="javascript"#{if _id} id="${_id}"#{/if}#{if _charset} charset="${_charset}"#{/if} src="/parse${_abs}"&gt;&lt;/script&gt; </code></pre> <p>It works exactly like the <code>#{script /}</code> tag, but parses the file before returning it: <code>#{parsescript 'test.js' /}</code></p> <p>One could equally shamelessly hack the <code>#{stylesheet /}</code> tag, but I think I've taken up enough space already.</p> <hr>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload