std:resources
This template always renders as an empty string, but as a side effect, sets CSS and client side JavaScript resources to be included in the generated HTML page.
This only works when you’re using the default HTML layout. If you’re generating the entire page yourself, you’ll have to write your own tags.
This is intended for generated CSS and JavaScript files, not static files. If you want to include files in your static
folder, it’s much easier to use the std:plugin:resources()
template function, or call the useStaticResource()
function on the Response
object.
Obtain a Template
object with P.template("std:resources")
, or use the template:std:resources()
template function.
View
key javascript
Either a single String
, or an Array
of strings. Each string is the pathname of a JavaScript resource available on this server, and must begin with /
. A <script>
tag will be generated for each pathname.
key css
As javascript
, but generates <link>
tags to include CSS files.
Example
Template
within(resources) { template:std:resources() } pageTitle("Including resources", <h2> "A title" </h2> <p> "..." </p>
Request handler
P.respond("GET", "/do/example/test", [ ], function(E) { E.render({ "resources": { css: "/api/example/generated_css", javascript: [ "/api/example/generated_javascript_one", "/api/example/generated_javascript_two" ] } }); });
The pathnames of the example files refer to other request handlers for this plugin. They’ll send the correct MIME type so the browser knows what to do with the files.