Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Using the tip above about dynamicHelpers, and the magic of closures, I found a fairly elegant solution that works without involving the request object. The trick is to wrap the page title variable in a closure that provides a get() and set() function around it, and make that wrapper object the result of the page_title dynamic helper. </p> <p>Create a property.js: </p> <pre><code>exports.create = function () { var value = null; return { get: function () { return value; }, set: function (new_value) { value = new_value; } }; } </code></pre> <p>So calling create() returns an object with a get() and set() method on it, that get and set the closure variable.</p> <p>Then, in your app's setup code:</p> <pre><code> var property = require("./property.js"); app.dynamicHelpers ({ page_title: function () { return property.create (); } }); </code></pre> <p>Since the dynamic helper's value is the result of calling its function, in your view and template, the page_title variable will be the wrapper object with the get() and set() functions.</p> <p>In your view, you can then say:</p> <pre><code>- page_title.set ("my specific page title"); </code></pre> <p>And in your layout:</p> <pre><code>title= page_title.get() </code></pre> <p>To simplify this a bit further, adding this to property.js:</p> <pre><code>exports.creator = function () { return function () { return exports.create(); }; } </code></pre> <p>Lets you simplify the dynamic helpers declaration block to this:</p> <pre><code> var property = require("./property.js"); app.dynamicHelpers ({ page_title: property.creator() }); </code></pre>
 

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