Skip to content
Myr

In depth partial docs

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 e98f86c · Browse files · 4 files+171 added−0 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+171 added−0 removed

  • other:+171 added−0 removed

4 files+171 added−0 removed

modified:docs/api.html+3 added
952 unmodified lines
953 <span class="variable">layout</span> = <span class="variable">layout</span> === <span class="variable">true</span>954 ? <span class="string">'layout'</span> + <span class="variable">ext</span>955 : <span class="variable">layout</span>;956957 <span class="comment">// Normalize &quot;context&quot; to &quot;scope&quot;</span>958 <span class="variable">options</span>.<span class="variable">scope</span> = <span class="variable">options</span>.<span class="variable">scope</span> || <span class="variable">options</span>.<span class="variable">context</span>;959960 <span class="comment">// Auto-cache in production</span>961 <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">app</span>.<span class="variable">set</span>(<span class="string">'env'</span>) === <span class="string">'production'</span>) {962 <span class="variable">options</span>.<span class="variable">cache</span> = <span class="variable">true</span>;963 }
72 unmodified lines
modified:docs/guide.1+81 added
703 unmodified lines
704\fIdebug\fR Output debugging information705.706.IP "" 0707.708.SS "res\.partial(view[, options])"709Render \fIview\fR partial with the given \fIoptions\fR\. This method is always available to the view as a local variable\.710.711.IP "\(bu" 4712\fIas\fR Variable name for each \fIcollection\fR value, defaults to the view name\.713.714.IP "\(bu" 4715as: \'something\' will add the \fIsomething\fR local variable716.717.IP "\(bu" 4718as: this will use the collection value as the template context719.720.IP "\(bu" 4721as: global will merge the collection value\'s properties with \fIlocals\fR722.723.IP "" 0724725.726.IP "\(bu" 4727\fIcollection\fR Array of objects, the name is derived from the view name itself\. For example \fIvideo\.html\fR will have a object \fIvideo\fR available to it\.728.729.IP "" 0730.731.P732The following are equivalent, and the name of collection value when passed to the partial will be \fImovie\fR as derived from the name\.733.734.IP "" 4735.736.nf737738partial(\'movie\.jade\', { collection: movies });739partial(\'movie\.jade\', movies);740partial(\'movie\', movies);741// In view: movie\.director742.743.fi744.745.IP "" 0746.747.P748To change the local from \fImovie\fR to \fIvideo\fR we can use the \"as\" option:749.750.IP "" 4751.752.nf753754partial(\'movie\', { collection: movies, as: \'video\' });755// In view: video\.director756.757.fi758.759.IP "" 0760.761.P762Also we can make our movie the value of \fIthis\fR within our view so that instead of \fImovie\.director\fR we could use \fIthis\.director\fR\.763.764.IP "" 4765.766.nf767768partial(\'movie\', { collection: movies, as: this });769// In view: this\.director770.771.fi772.773.IP "" 0774.775.P776Another alternative is to \"explode\" the properties of the collection item into pseudo globals (local variables) by using \fIas: global\fR, which again is syntactic sugar:777.778.IP "" 4779.780.nf781782partials(\'movie\', { collection: movies, as: global });783// In view: director784.785.fi786.787.IP "" 0788.789.SS "app\.set(name[, val])"790Apply an application level setting \fIname\fR to \fIval\fR, or get the value of \fIname\fR when \fIval\fR is not present:791.792.IP "" 4
172 unmodified lines
modified:docs/guide.html+49 added
188 unmodified lines
189<li><a href="#res-download-file-filename-">res.download()</a></li>190<li><a href="#res-send-body-status-headers-status-status-">res.send()</a></li>191<li><a href="#res-redirect-url-status-">res.redirect()</a></li>192<li><a href="#res-render-view-options-fn-">res.render()</a></li>193<li><a href="#res-partial-view-options-">res.partial()</a></li>194<li><a href="#app-set-name-val-">app.set()</a></li>195<li><a href="#app-enable-name-">app.enable()</a></li>196<li><a href="#app-disable-name-">app.disable()</a></li>197<li><a href="#app-configure-env-function-function-">app.configure()</a></li>
495 unmodified lines
693<li><em>debug</em> Output debugging information</li>694</ul>695696697<h3 id="res-partial-view-options-">res.partial(view[, options])</h3>698699<p>Render <em>view</em> partial with the given <em>options</em>. This method is always available700to the view as a local variable.</p>701702<ul>703<li><p><em>as</em> Variable name for each <em>collection</em> value, defaults to the view name.</p>704705<ul>706<li>as: 'something' will add the <em>something</em> local variable</li>707<li>as: this will use the collection value as the template context</li>708<li>as: global will merge the collection value's properties with <em>locals</em></li>709</ul>710</li>711<li><p><em>collection</em> Array of objects, the name is derived from the view name itself.712For example <em>video.html</em> will have a object <em>video</em> available to it.</p></li>713</ul>714715716<p>The following are equivalent, and the name of collection value when passed717to the partial will be <em>movie</em> as derived from the name.</p>718719<pre><code>partial('movie.jade', { collection: movies });720partial('movie.jade', movies);721partial('movie', movies);722// In view: movie.director723</code></pre>724725<p>To change the local from <em>movie</em> to <em>video</em> we can use the "as" option:</p>726727<pre><code>partial('movie', { collection: movies, as: 'video' });728// In view: video.director729</code></pre>730731<p>Also we can make our movie the value of <em>this</em> within our view so that instead732of <em>movie.director</em> we could use <em>this.director</em>.</p>733734<pre><code>partial('movie', { collection: movies, as: this });735// In view: this.director736</code></pre>737738<p>Another alternative is to "explode" the properties of the collection item into739pseudo globals (local variables) by using <em>as: global</em>, which again is syntactic sugar:</p>740741<pre><code>partials('movie', { collection: movies, as: global });742// In view: director743</code></pre>744745<h3 id="app-set-name-val-">app.set(name[, val])</h3>746747<p>Apply an application level setting <em>name</em> to <em>val</em>, or748get the value of <em>name</em> when <em>val</em> is not present:</p>
107 unmodified lines
modified:docs/guide.md+38 added
433 unmodified lines
434 - _filename_ Filename used for the _cache_ option435 - _cache_ Cache intermediate JavaScript in memory436 - _debug_ Output debugging information437438### res.partial(view[, options])439440Render _view_ partial with the given _options_. This method is always available441to the view as a local variable.442443- _as_ Variable name for each _collection_ value, defaults to the view name.444 * as: 'something' will add the _something_ local variable445 * as: this will use the collection value as the template context446 * as: global will merge the collection value's properties with _locals_447448- _collection_ Array of objects, the name is derived from the view name itself. 449 For example _video.html_ will have a object _video_ available to it.450451The following are equivalent, and the name of collection value when passed452to the partial will be _movie_ as derived from the name.453454 partial('movie.jade', { collection: movies });455 partial('movie.jade', movies);456 partial('movie', movies);457 // In view: movie.director458459To change the local from _movie_ to _video_ we can use the "as" option:460461 partial('movie', { collection: movies, as: 'video' });462 // In view: video.director463464Also we can make our movie the value of _this_ within our view so that instead465of _movie.director_ we could use _this.director_.466467 partial('movie', { collection: movies, as: this });468 // In view: this.director469470Another alternative is to "explode" the properties of the collection item into471pseudo globals (local variables) by using _as: global_, which again is syntactic sugar:472473 partials('movie', { collection: movies, as: global });474 // In view: director475476### app.set(name[, val])477478Apply an application level setting _name_ to _val_, or479get the value of _name_ when _val_ is not present:
90 unmodified lines