partial.js logo
Latest version
v1.3.1 (RC2)

How do "views" work?

"Views" serve for renderig of HTML. You can render "view" in "view" and "view" is rendered into the layout at the end.


Repository vs. Model

Into views you can transfer variable through controller.repository or controller.view('name', model).

function some_action() {
	var self = this;

	self.repository.firstname = 'Peter';
	self.repository.lastname = 'Sirka';

	self.view('my-view', { firstname: 'Janko', lastname: 'Hrasko' });

Repository vs. Model

View: /views/my-view.html

@{repository.firstname} or @{model.firstname}

Layout: /views/_layout.html

controller.repository works also in a layout. Model doesn't work because model is for current view and view can contains many other views.

In layout only works: @{repository.firstname}

<!-- The model can be only for current view, why? -->
<div>@{view('footer', { company: '' })}<div>

Define a layout

You can define a lot of layout files.

<!DOCTYPE html>
    <meta charset="utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=10" />
	<meta name="format-detection" content="telephone=no" />
	<meta name="viewport" content="width=1024, user-scalable=yes" />
	<meta name="robots" content="all,follow" />
	<script type="text/javascript" src="//"></script>
	<div class="content">
		<!-- Here is rendered a content from views -->

Define a view

You can create a lot of view files.

@{meta('Title', 'Description (optional)', 'Keywords (optional)')}

<div>Hello World!</div>

@{template('products', [{ name: 'A', price: 23.32 }, { name: 'B', price: 32.10 }])}

@{template('users', model)}

<!-- Look into definition of custom helper -->
@{customHelper('Hello', 2 + 3)}

<!-- You can define multi-line command -->

@{template('products', [{ name: 'A', price: 23.32 },
                        { name: 'B', price: 32.10 },
                        { name: 'C', price: 15.22 }])}

Views conditions

Views supports simple conditions. Example:
@{if (user === null)}
	<div>sign in</div>
	<div>sign up</div>

<br />
<br />

@{if ( === 'Peter')}
	<div>Here is Peter</div>

<br />
<br />

@{if ( !== 'Peter')}
	<div>Here is @{}</div>


Dynamic rendering

View function can compile a view template dynamically.
<!-- VIEW -->
', { name: 'Peter Širka' })} <!-- TEMPLATE --> @{template('
', [{name: 'Peter Širka'},{name: 'Steve Jobs'}])}

Define custom helper

Write code into a definition.

framewoker.helpers.customHelper = function(str, num) {
	// this === controller
	return str + ' = ' + num;


Prefixes for mobile devices
EXAMPLE: Prefixes (multi-devices development)

Auto-bindings models

Auto-bindings models


function view_contactform() {
	this.view('contactform', { Email: '@', Name: 'Ano<n>ym' });


Email: @{input('Email')}
Name: @{input('Name')}


Email: <input type="text" name="Email" value="@" />
Name: <input type="text" name="Name" value="Ano&lt;n&gt;ym" />

Download Sublime Text 2 syntax

Download syntax (4.9 kB)
Download the file, unpack and read readme.txt
partial.js syntax for Sublime TExt 2 editor