The main idea of Model object is to enable sending some context from page to template.
Lets say I have 2 files in Data folder with following structure:
name: Conference 1
date: 1st February 2018
organizers:
- ...
speakers:
- ...
partners:
- ...
And I have the following template:
{{# Data.conferences.conference1.sessions }}
<div>
<h6>{{ title }}</h6>
<p>{{ description }}</p>
<img src="{{ speaker.photoUrl }}" alt="{{ speaker.name }}" />
<h5>{{ speaker.name }}</h5>
<p>{{ speaker.bio }}</p>
<ul>
{{# speaker.links }}
<li><a target="_blank" href="{{ . }}">{{ . }}</a></li>
{{/ speaker.links }}
</ul>
</div>
{{/ Data.conferences.conference1.sessions }}
The issue here is that conference1 is the part of the template, not page. So, if I want to create 10 pages for different conferences I need to create 10 templates which will be the same, but bind them to different nodes in global Data object.
The solution is to introduce a new Model object and make it work like model in MVC concept, assuming than page will play the role of the controller and template will play the role of view.
My new template will look like this:
{{# Model.conference.sessions }}
<div>
<h6>{{ title }}</h6>
<p>{{ description }}</p>
<img src="{{ speaker.photoUrl }}" alt="{{ speaker.name }}" />
<h5>{{ speaker.name }}</h5>
<p>{{ speaker.bio }}</p>
<ul>
{{# speaker.links }}
<li><a target="_blank" href="{{ . }}">{{ . }}</a></li>
{{/ speaker.links }}
</ul>
</div>
{{/ Model.conference.sessions }}
And my page will look like this:
title: Conference 1
template: conference.hjs
Model.conference: Data.conferences.conference1
---
# This is Conference 1
Be aware, that we need to treat Data.conferences.conference1 not like a string, but like a value. It also means that now we will be able to start processing of all our pages only after we finished with all data files.
The main idea of
Modelobject is to enable sending some context from page to template.Lets say I have 2 files in
Datafolder with following structure:And I have the following template:
The issue here is that
conference1is the part of the template, not page. So, if I want to create 10 pages for different conferences I need to create 10 templates which will be the same, but bind them to different nodes in globalDataobject.The solution is to introduce a new
Modelobject and make it work like model in MVC concept, assuming than page will play the role of the controller and template will play the role of view.My new template will look like this:
And my page will look like this:
Be aware, that we need to treat
Data.conferences.conference1not like a string, but like a value. It also means that now we will be able to start processing of all our pages only after we finished with all data files.