Antidot PHP API  version 0.16.0
##PHP API to simplify integration of Antidot components
 All Classes Files Functions Variables Groups Pages
PHP templates in details

They are available here: https://github.com/antidot/API/tree/master/PHP/doc/data/templates. But for convenience, content of each template file is given below.

On GNU/Linux, these templates can be copied in /var/www/php-example/templates.

Templates will not be detaillled. If necessary, more documentation is available at Twig website.

Main template

This template is called to render the HTML page.

meta_template.html

<!DOCTYPE html>
<html>
<head>
<title>Antidot PHP API - Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="../../assets/js/html5shiv.js"></script>
<script src="../../assets/js/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="page-header">
<h1>Example <small>based on the Antidot PHP API</small></h1>
</div>
<div class="row">
<div class="col-md-5"></div>
<div class="input-group col-md-2">
<form method="get" action="" role="form" class="input-group">
<span class="input-group-addon">Search</span>
<input type="search" name="query" class="form-control" placeholder="Keywords" />
<span class="input-group-btn">
<button class="btn btn-primary" type="submit"><span class="glyphicon glyphicon-search"></span></button>
</span>
</form>
</div>
</div>
{{ include('spellcheck_template.html', {spellchecks: spellchecks}, with_context=false) }}
{% for replyset in replysets %}
<div class="">
<h1>Feed <span class="label label-default">{{ replyset.meta.feed }}</span> / Producer<span class="label label-info">{{ replyset.meta.producer }}</span></h1>
<div class="row">
{{ include('facet_template.html', {facets: replyset.facets}, with_context=false) }}
{{ include('result_template.html', {replies: replyset.replies, meta: replyset.meta}, with_context=false) }}
</div>
<div class="row">
{{ include('pager_template.html', {pager: replyset.pager}, with_context=false) }}
</div>
</div>
{% endfor %}
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="//code.jquery.com/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>

It first refers to spellcheck template in order to display suggestions provided by Antidot search engine. Then three other templates are called in a loop to display results of each replyset. All of these templates are described below.

Spellcheck template

spellcheck_template.html

{% if spellchecks %}
{% for feed, spellcheck in spellchecks %}
<div class="row">
<div class="input-group col-md-3">
<h2>Spellcheck for feed <span class="label label-default">{{ feed }}</span></h2>
{% for value in spellcheck %}
Suggestion: <a href="{{ value.link }}">{{ value.formatted|raw }}</a>
{% endfor %}
</div>
</div>
{% endfor %}
{% endif %}

A loop is used to display a list of all spellcheck values for each feed with suggestions.

Facet template

facet_template.html

{% if facets %}
<div class="col-md-3">
<h2>Filters</h2>
{% for facet in facets %}
<div class="panel panel-default">
<div class="panel-heading">{{ facet.label }}</div>
<div class="panel-body">
{% if facet.values is not empty %}
<div class="list-group">
{{ include('facet_values_template.html', {values: facet.values, depth: 0}, with_context=false) }}
</div>
{% endif %}
</div>
</div>
{% endfor %}
</div>
{% endif %}

It is quite easy to find the loop which allows to set up all facets. Then, in turn, this template refers specific template for facet values.

facet_values_template.html

<div class="list-group">
{% for value in values %}
<a class="list-group-item {{ value.active ? 'active' : '' }}" href="{{ value.link }}">{{ value.label }}<span class="badge">{{ value.count }}</span></a>
{% endfor %}
</div>

Here again, the loop allows to set up all values for each facet.

Result template

This template allows to render URI, title and abstract of each result. As discussed previously some additional work is necessary if you want to get access to client data.

result_template.html

<div class="col-md-9">
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-4">
<h2>Results <span class="label label-success">{{ meta.total_replies }}</span></h2>
<h4><span class="label label-info">Duration {{ meta.duration }} ms</span></h4>
</div>
</div>
<ul class="list-unstyled">
{% for reply in replies %}
<li>
<h3>{{ reply.title|raw }}</h3>
<p><a href="{{ reply.uri|raw }}">{{ reply.uri }}</a></p>
<p>{{ reply.abstract|raw }}</p>
</li>
{% endfor %}
</ul>
</div>

Pager template

This template generates simple pager at the bottom of the reply set. There is really no difficulty here.

pager_template.html

<div class="row">
<div class="col-md-5"></div>
<div class="input-group col-md-3">
<ul class="pagination">
{% for key, value in pager.pages %}
<li class="{{ key == pager.current ? 'active' : '' }}"><a href="{{ value }}">{{ key }}</a></li>
{% endfor %}
</ul>
</div>
</div>