Welcome to jqt

Editing is a rewording activity.
Alan J. Perlis

Could be jq the basis for a web template engine? Let’s explore…

jq

jq have nice features like string interpolation and implicit backtracking. Mixed with the help of some syntactic sugar a powerful template engine appear. Imagine the following interpolation strings, in a jq program, separated with the comma operator:

Simple expansion

..., "<title>\(.title)</title>", ...

Conditional expansion

..., "<meta name='date' content='\(.published//empty)' />", ...

Repeated expansion

..., "<meta name='author' content='\(.author[])' />", ...

In these examples the strings expand, vanish, or multiply without any explicit if or for!

jqt

To write jq scripts using strings with interpolations is not the idea we have for a template language. We need some syntactic sugar, and this is provided by jqt: you write templates in a very fashionable style, the templates are translated into a jq script and then jq is feed with the created script and some content and data in JSON format… and the magic is done!

Syntactic sugar

And, how do the syntactic sugar looks like? Do you think the following example seems to be a template?

<html lang='{{page.lang//site.lang}}'>
<head>
    <title>{{page.title | gsub("<[^>]*>"; "")}}</title>
    {# include files in preprocessing stage: #}
    <%include "head.html">
    <meta name="generator" content="JQT v<%version>"/>
    {# optional line: #}
    <meta name='dcterms.modified' content='{{page.updated//empty}}' />
    {# implicit loop for all authors: #}
    {% page.author | sort[] %}<meta name='author' content='{{.}}' />
</head>
<body>
    <h1>{{page.title}}</h1>
    <div id="CONTENT">
        {{$jqt._content}}
    </div>
    {# macro calls: #}
    <%partial analytics 'UA-82432866-1'>
</body>
</html>

Status

This site is built using jqt, and is itself in his implementation a kind of tutorial about jqt. If you want to learn how to use jqt see all the different sections of this site:

And don’t forget to study this documentation source code in the repository docs directory!

jqt is developed under the Fedora Linux distribution, and a lot of portability issues are expected at this stage of development. Please, use the project GitHub repository features if you want to collaborate or send any kind of questions.