Added view helper docs. Closes #344
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 9c3f6b0 · Browse files · 4 files·+65 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+65 added−3 removed
- other:+65 added−3 removed
Provenance
- Commit
c4b5208- Tree
87b670b- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
9c3f6b0
4 files changed+65 added−3 removed
modified:docs/api.html+5 added-3 removed
626 unmodified lines627 <span class="variable">next</span>();628 });629 630 <span class="comment">// Use router, expose as app.get(), etc</span>631- <span class="this">this</span>.<span class="variable">use</span>(<span class="variable">router</span>(<span class="keyword">function</span>(<span class="variable">app</span>){632- <span class="variable">self</span>.<span class="variable">routes</span> = <span class="variable">app</span>;633- }));631+ <span class="this">this</span>.<span class="variable">router</span> = <span class="variable">router</span>(<span class="keyword">function</span>(<span class="variable">app</span>){ <span class="variable">self</span>.<span class="variable">routes</span> = <span class="variable">app</span>; });632 };</code></pre>633 </td>634 </tr>635 <tr class="code">124 unmodified lines760 <span class="comment">// Generate routing methods</span>761 762 (<span class="keyword">function</span>(<span class="variable">method</span>){763 <span class="class">Server</span>.<span class="variable">prototype</span>[<span class="variable">method</span>] = <span class="keyword">function</span>(<span class="variable">path</span>, <span class="variable">fn</span>){764+ <span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">__usedRouter</span>) {765+ <span class="this">this</span>.<span class="variable">use</span>(<span class="this">this</span>.<span class="variable">router</span>);766+ <span class="this">this</span>.<span class="variable">__usedRouter</span> = <span class="variable">true</span>;767+ }768 <span class="this">this</span>.<span class="variable">routes</span>[<span class="variable">method</span>](<span class="variable">path</span>, <span class="variable">fn</span>);769 <span class="keyword">return</span> <span class="this">this</span>;770 };771 <span class="keyword">return</span> <span class="variable">arguments</span>.<span class="variable">callee</span>;278 unmodified linesmodified:docs/guide.1+29 added
499 unmodified lines500 _lastInCollection _ True if this is the last object501 .502 .IP "" 0503 .504+.SS "View Helpers"505+View helpers are merged with all template local variables, exposing them as pseudo globals\. Below is an example of exposing \fIfoo()\fR to all views:506+.507+.IP "" 4508+.509+.nf510+511+var view = require(\'express/view\');512+view\.helpers\.foo = function(){513+ return \'bar\';514+};515+.516+.fi517+.518+.IP "" 0519+.520+.P521+Which we could then utilize in a template as shown below:522+.523+.IP "" 4524+.525+.nf526+527+<%= foo() %>528+.529+.fi530+.531+.IP "" 0532+.533 .SS "Template Engines"534 Below are a few template engines commonly used with Express:535 .536 .IP "\(bu" 4520 unmodified linesmodified:docs/guide.html+17 added
174 unmodified lines175 <li><a href="#Middleware">Middleware</a></li>176 <li><a href="#Error-Handling">Error Handling</a></li>177 <li><a href="#View-Rendering">View Rendering</a></li>178 <li><a href="#View-Partials">View Partials</a></li>179+<li><a href="#View-Helpers">View Helpers</a></li>180 <li><a href="#Template-Engines">Template Engines</a></li>181 <li><a href="#req-header-key-defaultValue-">req.header()</a></li>182 <li><a href="#req-accepts-type-">req.accepts()</a></li>183 <li><a href="#req-param-name-">req.param()</a></li>349 unmodified lines533 <li>_lastInCollection _ True if this is the last object</li>534 </ul>535 536 537+<h3 id="View-Helpers">View Helpers</h3>538+539+<p>View helpers are merged with all template local variables, exposing them540+as pseudo globals. Below is an example of exposing <em>foo()</em> to all views:</p>541+542+<pre><code>var view = require('express/view');543+view.helpers.foo = function(){544+ return 'bar';545+};546+</code></pre>547+548+<p>Which we could then utilize in a template as shown below:</p>549+550+<pre><code><%= foo() %>551+</code></pre>552+553 <h3 id="Template-Engines">Template Engines</h3>554 555 <p>Below are a few template engines commonly used with Express:</p>556 349 unmodified linesmodified:docs/guide.md+14 added
286 unmodified lines287 * _firstInCollection_ True if this is the first object288 * _indexInCollection_ Index of the object in the collection289 * _lastInCollection _ True if this is the last object290 291+### View Helpers292+293+View helpers are merged with all template local variables, exposing them294+as pseudo globals. Below is an example of exposing _foo()_ to all views:295+296+ var view = require('express/view');297+ view.helpers.foo = function(){298+ return 'bar';299+ };300+301+Which we could then utilize in a template as shown below:302+303+ <%= foo() %>304+305 ### Template Engines306 307 Below are a few template engines commonly used with Express:308 301 unmodified lines