Skip to content

Instantly share code, notes, and snippets.

@jdf-id-au
Last active August 11, 2021 00:09
Show Gist options
  • Save jdf-id-au/2cda1521ae477ac324697cdf07d62353 to your computer and use it in GitHub Desktop.
Save jdf-id-au/2cda1521ae477ac324697cdf07d62353 to your computer and use it in GitHub Desktop.
Debugging nimWebTemplates
{% extends "parent.html" %}
{% block head %}
head!
{{key1}} {{key2}}
{% endblock %}
{% block content %}
content!
{{key1}} {{key2}}
{% endblock %}
import nwt
import json
var templates = newNwt("templates/*.html")
var context = %* {"key1": "one", "key2": "two"}
echo templates.renderTemplate("child.html", context)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
head!
one
content!
one two
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
{% block head %}
{% endblock %}
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
@jdf-id-au
Copy link
Author

jdf-id-au commented Oct 22, 2020

{{key2}} is not rendered in {% block head %}. </head> and <body> are also in the wrong position.

I think it's to do with incorrect calculation of posStart in fillBlocks* (which comes from getBlocks). Do you have any suggestions how to fix?

@enthus1ast
Copy link

the new incarnation of nwt does not have this issue: nimja

@jdf-id-au
Copy link
Author

brilliant!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment