If not provided, the earliest date present in the events is taken as start date.</td>
If not provided, the earliest date present in the events is taken as start date.</td>
</tr>
</tr>
<tr>
<td>template</td>
<td>Function</td>
<td>none</td>
<td>A template function used to generate the contents of the items. The function is called by the Timeline with an items data as argument, and must return HTML code as result. When the option template is specified, the items do not need to have a field <code>content</code>. See section <ahref="#Templates">Templates</a> for a detailed explanation.</td>
</tr>
<tr>
<tr>
<td>type</td>
<td>type</td>
<td>String</td>
<td>String</td>
@ -1068,6 +1076,80 @@ var options = {
A full example is available here: <ahref="../examples/timeline/08_edit_items.html">08_edit_items.html</a>.
A full example is available here: <ahref="../examples/timeline/08_edit_items.html">08_edit_items.html</a>.
<h2id="Templates">Templates</h2>
<p>
Timeline supports templates to format item contents. Any template engine (such as <ahref="http://handlebarsjs.com/">handlebars</a> or <ahref="http://mustache.github.io/">mustache</a>) can be used, and one can also manually build HTML. In the options, one can provide a template handler. This handler is a function accepting an items data as argument, and outputs formatted HTML:
</p>
<preclass="prettyprint lang-js">var options = {
template: function (item) {
var html = ... // generate HTML markup for this item
var source = document.getElementById('item-template').innerHTML;
var template = Handlebars.compile(source);
</pre>
And then specify the template in the Timeline options
<preclass="prettyprint lang-js">var options = {
template: template
};
</pre>
<h3>Multiple templates</h3>
In order to support multiple templates, the template handler can be extended to switch between different templates, depending on a specific item property:
<preclass="prettyprint lang-js">
var templates = {
template1: Handlebars.compile(...),
template2: Handlebars.compile(...),
template2: Handlebars.compile(...),
...
};
var options = {
template: function (item) {
var template = templates[item.template]; // choose the right template
return template(item); // execute the template
}
};
</pre>
Now the items can be extended with a property <code>template</code>, specifying which template to use for the item.
<h2id="Localization">Localization</h2>
<h2id="Localization">Localization</h2>
<p>
<p>
Timeline can be localized. For localization, Timeline depends largely on the localization of <ahref="http://momentjs.com">moment.js</a>. Locales are not included in vis.js by default. To enable localization, moment.js must be loaded with locales. Moment.js offers a bundle named "moment-with-locales.min.js" for this and there are various alternative ways to load locales.
Timeline can be localized. For localization, Timeline depends largely on the localization of <ahref="http://momentjs.com">moment.js</a>. Locales are not included in vis.js by default. To enable localization, moment.js must be loaded with locales. Moment.js offers a bundle named "moment-with-locales.min.js" for this and there are various alternative ways to load locales.