-
Notifications
You must be signed in to change notification settings - Fork 15
Views
alangrafu edited this page Jan 30, 2012
·
16 revisions
The [LODSPeaKr templating system](Templating system in LODSPeaKr) comprises model queries that feed view templates.
Similar to models, views are stored in the $LODSPEAKR_HOME
/views directory and have the form
CURIE.view.EXTENSION
Most of the time, the views are interesting when we want to publish HTML files (the templates for other formats is just a dump of a serialization). The views uses Haanga for templating. Thus, for example, the default view is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" {% for i, ns in base.ns %}xmlns:{{i}}="{{ns}}"
{%endfor%}version="XHTML+RDFa 1.0" xml:lang="en">
<head>
<title>Page about {{base.this.value}}</title>
<link href="{{base.baseUrl}}/lodspeakr/css/basic.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<h1>Page about <a href='{{base.this.value}}'>{{base.this.curie}}</a></h1>
<div>
<h2>Information from {{base.this.curie}}</h2>
<table about="{{base.this.value}}">
{% for row in r %}
{% if row.value.s1 != null %}
<tr>
<td><a href='{{ row.value.s1 }}'>{{row.curie.s1}}</a></td>
{% if row.uri.p1 == 1 %}
<td><a rel='{{row.s1.curie}}' href='{{row.value.p1}}'>{{row.curie.p1}}</a></td>
{% else %}
<td><span property='{{row.s1.curie}}'>{{row.value.p1}}</span></td>
{% endif %}
</tr>
{% endif %}
{% endfor %}
</table>
<br/><br/>
<h2>Information pointing to {{base.this.curie}}</h2>
<table about="{{base.this.value}}">
{% for row in r %}
{% if row.value.p2 != null %}
<tr>
<td><a href='{{row.value.s2 }}'>{{ row.curie.s2 }}</a></td>
<td><a href='{{row.value.p2}}'>{{row.curie.p2}}</a></td>
</tr>
{%endif %}
{% endfor %}
</table>
</div>
</body>
</html>
It is common that we need only the first value from a query. The normal way of selecting is doing
{% for row in r.someModel%}
{%if forloop.first%}
{{row.variable.value}}
{%endif%}
{%endfor%}
This is too verbose. A way to simplify this process is using first
instead of models
. We can produce the same output as above simply writing
{{first.someModel.variable.value}}
- Proposal-for-naming-convention-in-models-and-views for a potential redesign on naming.
- How to use results to obtain values from model queries when filling in view templates.