-
-
Save xiocode/6262166 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Assertions: | |
- I'm not stupid | |
- I don't want to be limited by some idiotic `people that write templates are stupid` rule. | |
- I don't want to learn yet another template language. | |
- I want to use golang expressions if, for.. | |
- I want all the power of indexing, getting attributes and performing operations that golang offers. | |
- I want to type less stuff and do more. | |
- I want to include other templates in my template. (jinja?) | |
- I want to extend templates. | |
Implementation: | |
After transformation the template.html will result in compilable golang code. | |
[] - used for blocks of code. | |
`` - used to print stuff to the template. | |
base.html: | |
<html> | |
[block title][endblock] | |
<body> | |
[block content] | |
Hello `var`. | |
[enblock] | |
</html> | |
template.html: | |
[import "fmt"] | |
[extend "base.html"] | |
[block content] | |
This is a loop: | |
<ul> | |
[for x := range a_list_of_maps] | |
[var y := 500] | |
[if something == 0] | |
<li id="`x[1] + y`">\[`x[0].some_attr`\]</li> | |
[endif] | |
[if something == x] | |
`fmt.Sprintf("a")` | |
[else if something == y] | |
b | |
[else] | |
c | |
[endif] | |
[endfor] | |
</ul> | |
[include "small.html"] | |
[endblock] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment