Skip to content
Myr

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

4 files+65 added−3 removed

modified:docs/api.html+5 added-3 removed
626 unmodified lines
627 <span class="variable">next</span>();628 });629630 <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 lines
760<span class="comment">// Generate routing methods</span>761762(<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 lines
modified:docs/guide.1+29 added
499 unmodified lines
500_lastInCollection _ True if this is the last object501.502.IP "" 0503.504.SS "View Helpers"505View 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.nf510511var view = require(\'express/view\');512view\.helpers\.foo = function(){513 return \'bar\';514};515.516.fi517.518.IP "" 0519.520.P521Which we could then utilize in a template as shown below:522.523.IP "" 4524.525.nf526527<%= foo() %>528.529.fi530.531.IP "" 0532.533.SS "Template Engines"534Below are a few template engines commonly used with Express:535.536.IP "\(bu" 4
520 unmodified lines
modified:docs/guide.html+17 added
174 unmodified lines
175<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 lines
533<li>_lastInCollection _ True if this is the last object</li>534</ul>535536537<h3 id="View-Helpers">View Helpers</h3>538539<p>View helpers are merged with all template local variables, exposing them540as pseudo globals. Below is an example of exposing <em>foo()</em> to all views:</p>541542<pre><code>var view = require('express/view');543view.helpers.foo = function(){544 return 'bar';545};546</code></pre>547548<p>Which we could then utilize in a template as shown below:</p>549550<pre><code>&lt;%= foo() %>551</code></pre>552553<h3 id="Template-Engines">Template Engines</h3>554555<p>Below are a few template engines commonly used with Express:</p>556
349 unmodified lines
modified:docs/guide.md+14 added
286 unmodified lines
287 * _firstInCollection_ True if this is the first object288 * _indexInCollection_ Index of the object in the collection289 * _lastInCollection _ True if this is the last object290291### View Helpers292293View helpers are merged with all template local variables, exposing them294as pseudo globals. Below is an example of exposing _foo()_ to all views:295296 var view = require('express/view');297 view.helpers.foo = function(){298 return 'bar';299 };300301Which we could then utilize in a template as shown below:302303 <%= foo() %>304305### Template Engines306307Below are a few template engines commonly used with Express:308
301 unmodified lines