-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathgenerated-documentation-djula-v0.2.html
1396 lines (777 loc) · 52.3 KB
/
generated-documentation-djula-v0.2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html>
<head>
<title>Djula Documentation</title>
<style type='text/css'>
a.djula-tag { text-decoration: none; color: darkblue; };
</style>
</head>
<body>
<h2>Djula Documentation Quick Reference</h2>
<ol>
<li><a href='#variables'>Variables</a></li>
<li><a href='#filters'>Filters</a></li>
<li><a href='#tags'>Tags</a></li>
<li><a href='#template-inheritance'>Template Inheritance</a></li>
<li><a href='#translation-variables'>Translation Variables</a></li>
<li><a href='#different-from-django'>How Djula is different from the Django templating language</a></li>
</ol>
<h2><a name='documentation'></a>Djula Documentation</h2>
<p>This is all based on the <a href='http://www.djangoproject.com/' target='_blank'>Django</a> templating language, if you are familiar it then Djula templates will be a breeze. In fact most of the text on this page was directly copied from <a href='http://www.djangoproject.com/documentation/templates/' target='_blank'>The Django template language: for template authors</a>. For a list of how Djula is different in from the Django templating language <a href='#different-from-django'>click here</a></p>
<h3><a name='variables'></a>Variables</h3>
<p>Variables look like this: <code><a href='#variables' class='djula-tag'>{{ variable }}<a></code>. When the template engine encounters a variable, it evaluates that variable and replaces it with the result.</p>
<p>Use a dot (<code>.</code>) to access attributes of a variable or index of a list. <code><a href='#variables' class='djula-tag'>{{ user.name }}<a></code> will be replaced with the <code>name</code> attribute of the <code>user</code> object (<i>Lisp hackers: this is an alist lookup</i>). <code><a href='#variables' class='djula-tag'>{{ users.1 }}<a></code> will be replaced with the first user object of the list <code>users</code>. You can use multiple dots with a variable, so <code><a href='#variables' class='djula-tag'>{{ users.1.name }}<a></code> will be replaced with the <code>name</code> attribute of the first user object of the list <code>users</code>.</p>
<p>When designing your templates, the values of variables come from Example Tables linked to the template by <a href='#tag-example-table' class='djula-tag'>{% example-table %}<a>
tags or directly from <a href='#tag-example' class='djula-tag'>{% example %}<a> tags. When your template is deployed in a real web application
these "devel" values are replaced with "real" values by the programmers.
</p>
<h3><a name='filters'>Filters</a></h3>
<p>You can modify variables for display by using filters.</p>
<p>Filters look like this: <code><a href='#variables' class='djula-tag'>{{ name|lowercase }}<a></code>. This displays the value of the <code><a href='#variables' class='djula-tag'>{{ name }}<a></code> after being filtered through the <code>lowercase</code> filter, which converts text to lowercase. Use a pipe (<code>|</code>) to apply a filter.</p>
<p>Filters can be "chained." The output of one filter is applied to the next. <code><a href='#variables' class='djula-tag'>{{ name|lowercase|urlencode }}<a></code> displays <code>name</code> after being lowercased and url-encoded.</p>
<p>Some filters take arguments. A filter argument looks like this: <code><a href='#variables' class='djula-tag'>{{ bio|truncatewords:30 }}<a></code>. This will display the first 30 words of the <code>bio</code> variable.</p>
<p>Filter arguments that contain spaces must be quoted; for example, to join a list with commas and spaced you’d use <code><a href='#variables' class='djula-tag'>{{ list|join:"," }}<a></code>.</p>
<p>The <a href='#known-filter-reference'>Known Filter Reference</a> below describes all the filters Djula currently knows about. You can create your own filters, too, if you know how to write Common Lisp code</p>
<h3>Known Filters</h3>
<ul>
<li><a href='#filter-capfirst'>CAPFIRST</a></li>
<li><a href='#filter-cut'>CUT</a></li>
<li><a href='#filter-default'>DEFAULT</a></li>
<li><a href='#filter-force_escape'>FORCE_ESCAPE</a></li>
<li><a href='#filter-length'>LENGTH</a></li>
<li><a href='#filter-linebreaks'>LINEBREAKS</a></li>
<li><a href='#filter-linebreaksbr'>LINEBREAKSBR</a></li>
<li><a href='#filter-lisp'>LISP</a></li>
<li><a href='#filter-lower'>LOWER</a></li>
<li><a href='#filter-safe'>SAFE</a></li>
<li><a href='#filter-truncatechars'>TRUNCATECHARS</a></li>
<li><a href='#filter-upper'>UPPER</a></li>
<li><a href='#filter-urlencode'>URLENCODE</a></li>
</ul>
<h3><a name='tags'></a>Tags</h3>
<p>Tags look like this: <code><a href='#tag-tag' class='djula-tag'>{% tag %}<a></code>. Tags are more complex than variables: Some create text in the output, some control flow by performing loops or logic, and some load external information into the template to be used by later variables.</p>
<p>Some tags require beginning and ending tags (i.e. <code><a href='#tag-tag' class='djula-tag'>{% tag %}<a> ... tag contents ... <a href='#tag-endtag' class='djula-tag'>{% endtag %}<a></code>). The <a href='#known-tag-reference'>known tag reference</a> below describes all the tags Djula knows about. You can create your own tags, too, if you know how to write Common Lisp code.</p>
<h3>Known Tags</h3>
<ul>
<li><a href='#tag-block'>BLOCK</a></li>
<li><a href='#tag-comment'>COMMENT</a></li>
<li><a href='#tag-cycle'>CYCLE</a></li>
<li><a href='#tag-debug'>DEBUG</a></li>
<li><a href='#tag-else'>ELSE</a></li>
<li><a href='#tag-elseif'>ELSEIF</a></li>
<li><a href='#tag-emit-js'>EMIT-JS</a></li>
<li><a href='#tag-endblock'>ENDBLOCK</a></li>
<li><a href='#tag-endcomment'>ENDCOMMENT</a></li>
<li><a href='#tag-endemit-js'>ENDEMIT-JS</a></li>
<li><a href='#tag-endfilter'>ENDFILTER</a></li>
<li><a href='#tag-endfor'>ENDFOR</a></li>
<li><a href='#tag-endif'>ENDIF</a></li>
<li><a href='#tag-endifchanged'>ENDIFCHANGED</a></li>
<li><a href='#tag-endifequal'>ENDIFEQUAL</a></li>
<li><a href='#tag-endifnotequal'>ENDIFNOTEQUAL</a></li>
<li><a href='#tag-example'>EXAMPLE</a></li>
<li><a href='#tag-example-table'>EXAMPLE-TABLE</a></li>
<li><a href='#tag-extends'>EXTENDS</a></li>
<li><a href='#tag-filter'>FILTER</a></li>
<li><a href='#tag-for'>FOR</a></li>
<li><a href='#tag-if'>IF</a></li>
<li><a href='#tag-ifchanged'>IFCHANGED</a></li>
<li><a href='#tag-ifequal'>IFEQUAL</a></li>
<li><a href='#tag-ifnotequal'>IFNOTEQUAL</a></li>
<li><a href='#tag-include'>INCLUDE</a></li>
<li><a href='#tag-js'>JS</a></li>
<li><a href='#tag-js-script'>JS-SCRIPT</a></li>
<li><a href='#tag-lisp'>LISP</a></li>
<li><a href='#tag-set-language'>SET-LANGUAGE</a></li>
<li><a href='#tag-show-language'>SHOW-LANGUAGE</a></li>
<li><a href='#tag-show-table'>SHOW-TABLE</a></li>
<li><a href='#tag-ssi'>SSI</a></li>
<li><a href='#tag-templatetag'>TEMPLATETAG</a></li>
<li><a href='#tag-translation'>TRANSLATION</a></li>
<li><a href='#tag-translation-table'>TRANSLATION-TABLE</a></li>
</ul>
<h3><a name='comments'></a>Comments</h3>
<p>Anything between <code><a href='#comments' class='djula-tag'>{#</code> and <code>#}<a></code> is commented out and will not appear in the browser.</p>
<p>So this:
<blockquote><code>Hello<a href='#comments' class='djula-tag'>{# this is a comment #}<a></code></blockquote>
will be displayed by the template as:
<blockquote>Hello</blockquote>
</p>
<h3><a name='template-inheritance'></a>Template Inheritance</h3>
<p>The most powerful - and thus the most complex - part of Djula’s template engine is template inheritance. Template inheritance allows you to build a base "skeleton" template that contains all the common elements of your site and defines blocks that child templates can override.</p>
<p>It’s easiest to understand template inheritance by starting with an example:</p>
<pre><code>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" href="style.css" />
<title><a href='#tag-block' class='djula-tag'>{% block title %}<a>My amazing site<a href='#tag-endblock' class='djula-tag'>{% endblock %}<a></title>
</head>
<body>
<div id="sidebar">
<a href='#tag-block' class='djula-tag'>{% block sidebar %}<a>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/blog/">Blog</a></li>
</ul>
<a href='#tag-endblock' class='djula-tag'>{% endblock %}<a>
</div>
<div id="content">
<a href='#tag-block' class='djula-tag'>{% block content %}<a><a href='#tag-endblock' class='djula-tag'>{% endblock %}<a>
</div>
</body>
</html>
</pre></code>
<p>This template, which we’ll call <i>base.html</i>, defines a simple HTML skeleton document that you might use for a simple two-column page. It’s the job of "child" templates to fill the empty blocks with content.</p>
</p>In this example, the <code><a href='#tag-block' class='djula-tag'>{% block %}<a></code> tag defines three blocks that child templates can fill in. All the block tag does is to tell the template engine that a child template may override those portions of the template.</p>
<p>A child template might look like this:</p>
<code><pre>
<a href='#tag-extends' class='djula-tag'>{% extends "base.html" %}<a>
<a href='#tag-block' class='djula-tag'>{% block title %}<a>My amazing blog<a href='#tag-endblock' class='djula-tag'>{% endblock %}<a>
<a href='#tag-block' class='djula-tag'>{% block content %}<a>
<a href='#tag-for' class='djula-tag'>{% for entry in blog_entries %}<a>
<h2><a href='#variables' class='djula-tag'>{{ entry.title }}<a></h2>
<p><a href='#variables' class='djula-tag'>{{ entry.body }}<a></p>
<a href='#tag-endfor' class='djula-tag'>{% endfor %}<a>
<a href='#tag-endblock' class='djula-tag'>{% endblock %}<a>
</code></pre>
<p>The <code><a href='#tag-extends' class='djula-tag'>{% extends %}<a></code> tag is the key here. It tells the template engine that this template "extends" another template. When the template system evaluates this template, first it locates the parent — in this case, <i>base.html</i>.</p>
<p>At that point, the template engine will notice the three <a href='#tag-block' class='djula-tag'>{% block %}<a> tags in <i>base.html</i> and replace those blocks with the contents of the child template. Depending on the value of blog_entries, the output might look like:</p>
<code><pre>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" href="style.css" />
<title>My amazing blog</title>
</head>
<body>
<div id="sidebar">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/blog/">Blog</a></li>
</ul>
</div>
<div id="content">
<h2>Entry one</h2>
<p>This is my first entry.</p>
<h2>Entry two</h2>
<p>This is my second entry.</p>
</div>
</body>
</html>
</pre></code>
<p>Note that since the child template didn’t define the sidebar block, the value from the parent template is used instead. Content within a <code><a href='#tag-block' class='djula-tag'>{% block %}<a></code> tag in a parent template is always used as a fallback.</p>
<p>You can use as many levels of inheritance as needed. One common way of using inheritance is the following three-level approach:</p>
<p>Create a <i>base.html</i> template that holds the main look-and-feel of your site.</p>
<p>Create a <i>base_SECTIONNAME.html</i> template for each "section" of your site. For example, <i>base_news.html</i>, <i>base_sports.html</i>. These templates all extend <i>base.html</i> and include section-specific styles/design.</p>
<p>Create individual templates for each type of page, such as a news article or blog entry. These templates extend the appropriate section template.</p>
<p>This approach maximizes code reuse and makes it easy to add items to shared content areas, such as section-wide navigation.</p>
<p>Here are some tips for working with inheritance:</p>
<p>If you use <code><a href='#tag-extends' class='djula-tag'>{% extends %}<a></code> in a template, it must be the first template tag in that template. Template inheritance won’t work, otherwise.</p>
<p>More <code><a href='#tag-block' class='djula-tag'>{% block %}<a></code> tags in your base templates are better. Remember, child templates don’t have to define all parent blocks, so you can fill in reasonable defaults in a number of blocks, then only define the ones you need later. It’s better to have more hooks than fewer hooks.</p>
<p>If you find yourself duplicating content in a number of templates, it probably means you should move that content to a <code><a href='#tag-block' class='djula-tag'>{% block %}<a></code> in a parent template.</p>
<p>If you need to get the content of the block from the parent template, the <a href='#variables' class='djula-tag'>{{ block.super }}<a> variable will do the trick. This is useful if you want to add to the contents of a parent block instead of completely overriding it. Data inserted using <a href='#variables' class='djula-tag'>{{ block.super }}<a> will not be automatically escaped (see the next section), since it was already escaped, if necessary, in the parent template.</p>
<p>For extra readability, you can optionally give a name to your <code><a href='#tag-endblock' class='djula-tag'>{% endblock %}<a></code> tag. For example:</p>
<pre><code>
<a href='#tag-block' class='djula-tag'>{% block content %}<a>
...
<a href='#tag-endblock' class='djula-tag'>{% endblock content %}<a>
</code></pre>
<p>In larger templates, this technique helps you see which <a href='#tag-block' class='djula-tag'>{% block %}<a> tags are being closed.</p>
<p>Finally, note that you can’t define multiple <code><a href='#tag-block' class='djula-tag'>{% block %}<a></code> tags with the same name in the same template. This limitation exists because a block tag works in “both” directions. That is, a block tag doesn’t just provide a hole to fill — it also defines the content that fills the hole in the parent. If there were two similarly-named <a href='#tag-block' class='djula-tag'>{% block %}<a> tags in a template, that template’s parent wouldn’t know which one of the blocks’ content to use.</p>
<h3><a name='translation-variables'></a>Translation Variables</h3>
<p>
Translation Variables look like <a href='#translation-variables' class='djula-tag'>{_this_}<a>.
Translation Variables are like <a href='#variables'>variables</a> except they are not HTML-escaped, the don't take filters,
and they get their values from Translation Tables linked to the template by
<a href='#tag-translation-table' class='djula-tag'>{% translation-table %}<a> tags or
from <a href='#tag-translation' class='djula-tag'>{% translation %}<a> tags.
</p>
<p>
Translation Variables are used for internationalization. If the Translation Table "/foo.lisp" contains the following definitions:
<p>
<code><pre>
(foo english "The foo" spanish "El foo")
(bar english "The bar" spanish "El bar")
</pre><code>
<p>Then the following template:</p>
<code><pre>
<a href='#tag-translation-table' class='djula-tag'>{% translation-table "/foo.lisp" %}<a>
<a href='#translation-variables' class='djula-tag'>{_foo_}<a>... <a href='#translation-variables' class='djula-tag'>{_bar_}<a>...
</pre></code>
<p>Will be rendered in English to:</p>
<code><pre>
The foo... The bar...
</pre></code>
<p>and in Spanish to:</p>
<code><pre>
El foo... El bar...
</pre></code>
<p>
Note that translation values can have nested <a href='#tags'>tags</a>, <a href='#variables'>variables</a>, <a href='#comments'>comments</a>, etc.
</p>
<h3><a name='known-tag-reference'></a>Known Tag Reference</h3>
<p>
<ul>
<li><a name='tag-block'></a>
<p><pre><b>BLOCK (NAME)</b></pre><p>
<p><pre>Define a block that can be overridden by child templates. Read the documentation
about "Template inheritance" for more information.</pre></p>
<p><pre><b>Different from Django because:</b> <a href='#variables' class='djula-tag'>{{block.super}}<a> is currently broken</pre></p>
</li>
<li><a name='tag-comment'></a>
<p><pre><b>COMMENT</b></pre><p>
<p><pre>Ignore everything between <a href='#tag-comment' class='djula-tag'>{% comment %}<a> and <a href='#tag-endcomment' class='djula-tag'>{% endcomment %}<a></pre></p>
</li>
<li><a name='tag-cycle'></a>
<p><pre><b>CYCLE (&REST LIST)</b></pre><p>
<p><pre>Cycle among the given strings or variables each time this tag is encountered.
Within a loop, cycles among the given strings/variables each time through the loop:
<a href='#tag-for' class='djula-tag'>{% for o in some_list %}<a>
<tr class="<a href='#tag-cycle' class='djula-tag'>{% cycle 'row1' 'row2' rowvar %}<a>">
...
</tr>
<a href='#tag-endfor' class='djula-tag'>{% endfor %}<a>
You can use any number of values, separated by spaces. Values enclosed in double quotes
(") are treated as string literals, while values without quotes are assumed to
refer to context variables.</pre></p>
<p><pre><b>Different from Django because:</b> In Djula templates <a href='#tag-cycle' class='djula-tag'>{% cycle %}<a> is only usefull inside a <a href='#tag-for' class='djula-tag'>{% for %}<a> loop, the Django
behavior of <a href='#tag-cycle' class='djula-tag'>{% cycle %}<a> outside of a loop has not been replicated. Also, you have to
use double qoutes ("), you can't use single quotes to identity string literals.
Cycling between variables [not string literals] is currently broken.</pre></p>
</li>
<li><a name='tag-debug'></a>
<p><pre><b>DEBUG</b></pre><p>
<p><pre>Output a whole load of debugging information.</pre></p>
<p><pre><b>Different from Django because:</b> Most tags in Djula only effect the part of the template _after_ [or "below"] the tag.
So if you put a <a href='#tag-debug' class='djula-tag'>{% debug %}<a> tag at he top of a template and a <a href='#tag-debug' class='djula-tag'>{% debug %}<a> tag at the
bottom of the template they might display different information, depending on the tags
seen in between them</pre></p>
</li>
<li><a name='tag-else'></a>
<p><pre><b>ELSE</b></pre><p>
<p><pre>See <a href='#tag-if' class='djula-tag'>{% if %}<a></pre></p>
</li>
<li><a name='tag-elseif'></a>
<p><pre><b>ELSEIF (VAR)</b></pre><p>
<p><pre>See <a href='#tag-if' class='djula-tag'>{% if %}<a></pre></p>
</li>
<li><a name='tag-emit-js'></a>
<p><pre><b>EMIT-JS</b> <i><a href='#different-from-django'>New, not in Django</a></i></pre><p>
<p><pre>prints <script/> elements for all the <a href='#tag-js' class='djula-tag'>{% js %}<a> and <a href='#tag-js-script' class='djula-tag'>{% js-script %}<a> tags seen thus far
in the template, in order.
see also <a href='#tag-js' class='djula-tag'>{% js %}<a> and <a href='#tag-js-script' class='djula-tag'>{% js-script %}<a>
</pre></p>
</li>
<li><a name='tag-endblock'></a>
<p><pre><b>ENDBLOCK (&OPTIONAL BLOCKNAME)</b></pre><p>
<p><pre>Ends a block created by a <a href='#tag-block' class='djula-tag'>{% block %}<a> tag. Read the documentation about "Template
inheritance" for more information.</pre></p>
</li>
<li><a name='tag-endcomment'></a>
<p><pre><b>ENDCOMMENT</b></pre><p>
<p><pre>See <a href='#tag-comment' class='djula-tag'>{% comment %}<a></pre></p>
</li>
<li><a name='tag-endemit-js'></a>
<p><pre><b>ENDEMIT-JS</b> <i><a href='#different-from-django'>New, not in Django</a></i></pre><p>
<p><pre>See <a href='#tag-emit-js' class='djula-tag'>{% emit-js %}<a></pre></p>
</li>
<li><a name='tag-endfilter'></a>
<p><pre><b>ENDFILTER</b></pre><p>
<p><pre>See <a href='#tag-filter' class='djula-tag'>{% filter %}<a></pre></p>
</li>
<li><a name='tag-endfor'></a>
<p><pre><b>ENDFOR</b></pre><p>
<p><pre>See <a href='#tag-for' class='djula-tag'>{% for %}<a></pre></p>
</li>
<li><a name='tag-endif'></a>
<p><pre><b>ENDIF</b></pre><p>
<p><pre>See <a href='#tag-if' class='djula-tag'>{% if %}<a></pre></p>
</li>
<li><a name='tag-endifchanged'></a>
<p><pre><b>ENDIFCHANGED</b></pre><p>
<p><pre>See <a href='#tag-ifchanged' class='djula-tag'>{% ifchanged %}<a></pre></p>
</li>
<li><a name='tag-endifequal'></a>
<p><pre><b>ENDIFEQUAL</b></pre><p>
<p><pre>see <a href='#tag-ifequal' class='djula-tag'>{% ifequal %}<a></pre></p>
</li>
<li><a name='tag-endifnotequal'></a>
<p><pre><b>ENDIFNOTEQUAL</b></pre><p>
<p><pre>see <a href='#tag-ifnotequal' class='djula-tag'>{% ifnotequal %}<a></pre></p>
</li>
<li><a name='tag-example'></a>
<p><pre><b>EXAMPLE (VARIABLE-NAME LANGUAGE/VALUE-PLIST)</b> <i><a href='#different-from-django'>New, not in Django</a></i></pre><p>
<p><pre>the <a href='#tag-example' class='djula-tag'>{% example %}<a> tag enables the designer to provide example data without
involving an example table [see <a href='#tag-example-table' class='djula-tag'>{% example-table %}<a>]
so, during development, if there is a tag
<a href='#tag-example' class='djula-tag'>{% example user "Nick" %}<a>
then subsequent occurences of
<a href='#variables' class='djula-tag'>{{user}}<a>
will show up as
Nick
see also: <a href='#tag-example-table' class='djula-tag'>{% example-table %}<a></pre></p>
</li>
<li><a name='tag-example-table'></a>
<p><pre><b>EXAMPLE-TABLE (TEMPLATE-PATH)</b> <i><a href='#different-from-django'>New, not in Django</a></i></pre><p>
<p><pre>the <a href='#tag-example-table' class='djula-tag'>{% example-table %}<a> tag enables the designer to link to a file full of example
data to use when creating templates for a web applicaion. the values in this file
will later be replaced with real data by the programmer when the templates are used
in the running application.
the example table functions as a contracts between the designer and the programmer:
the programmer makes sure that the data coming from the application matches the
examples and the designer makes sure data that looks like the examples is displayed
correctly.
Examle tables must be filled with key/val pairs where the keys are lisp keywords
mapping to variables and the values are lisp objects [strings, numbers, lists,
plists, etc.]
If the example table "/example.foo.sexp" contains:
progress "Complete"
user (name "Nick" drinking "mimosa")
and there is a tag
<a href='#tag-example-table' class='djula-tag'>{% example-table "/example.foo.sexp" %}<a>
somewhere at the top of the template, then
<a href='#variables' class='djula-tag'>{{progress}}<a>
will be seen as
Complete
and
<a href='#variables' class='djula-tag'>{{user.name}}<a> is drinking a <a href='#variables' class='djula-tag'>{{user.drinking}}<a>
will be seen as
Nick is drinking a mimosa
The name of an example table must match one of the regular expressions in the
list *EXAMPLE-TABLE-REGEXEPS*. By default, an example table must look like:
example.XYZ.sexp
example.XYZ.lisp
example.XYZ.cl
see also: <a href='#tag-example' class='djula-tag'>{% example %}<a>, <a href='#tag-show-table' class='djula-tag'>{% show-table %}<a></pre></p>
</li>
<li><a name='tag-extends'></a>
<p><pre><b>EXTENDS (NAME)</b></pre><p>
<p><pre>Signal that this template extends a parent template. The form
<a href='#tag-extends' class='djula-tag'>{% extends "base.html" %}<a>
uses the literal value "base.html" as the name of the parent template to extend.
See Template inheritance for more information.</pre></p>
<p><pre><b>Different from Django because:</b> Literal values must be double-quoted ("") [not single-quoted ('')]. You cannot give
<a href='#tag-extends' class='djula-tag'>{% extends %}<a> a variable, you must give it a hard-coded string. Note: Djula knows about
your template directory, so you can give it an absolute path starting at the base of the
template directory, not just relative paths starting at the current template.</pre></p>
</li>
<li><a name='tag-filter'></a>
<p><pre><b>FILTER (FILTERS)</b></pre><p>
<p><pre>Filter the contents of the variable through variable filters.
Filters can also be piped through each other, and they can have arguments — just like
in variable syntax.
Sample usage:
<a href='#tag-filter' class='djula-tag'>{% filter force_escape|lower %}<a>
This text will be HTML-escaped, and will appear in all lowercase.
<a href='#tag-endfilter' class='djula-tag'>{% endfilter %}<a></pre></p>
</li>
<li><a name='tag-for'></a>
<p><pre><b>FOR (VAR IN LIST &OPTIONAL REVERSED)</b></pre><p>
<p><pre>Loop over each item in an array. For example, to display a list of athletes provided
in athlete_list:
<ul>
<a href='#tag-for' class='djula-tag'>{% for athlete in athlete_list %}<a>
<li><a href='#variables' class='djula-tag'>{{ athlete.name }}<a></li>
<a href='#tag-endfor' class='djula-tag'>{% endfor %}<a>
</ul>
You can loop over a list in reverse by using <a href='#tag-for' class='djula-tag'>{% for obj in list reversed %}<a>.
The for loop sets a number of variables available within the loop:
Variable Description
forloop.counter The current iteration of the loop (1-indexed)
forloop.counter0 The current iteration of the loop (0-indexed)
forloop.revcounter The number of iterations from the end of the loop (1-indexed)
forloop.revcounter0 The number of iterations from the end of the loop (0-indexed)
forloop.first True if this is the first time through the loop
forloop.last True if this is the last time through the loop
forloop.parentloop For nested loops, this is the loop "above" the current one</pre></p>
<p><pre><b>Different from Django because:</b> In the development version of Django you can unpack values in sublists with commas.
You can't do that with Djula yet</pre></p>
</li>
<li><a name='tag-if'></a>
<p><pre><b>IF (VAR)</b></pre><p>
<p><pre>The <a href='#tag-if' class='djula-tag'>{% if %}<a> tag evaluates a variable, and if that variable is 'true' (i.e. exists, is
not empty, and is not a false boolean value) the contents of the block are output:
<a href='#tag-if' class='djula-tag'>{% if athlete_list %}<a>
Number of athletes: <a href='#variables' class='djula-tag'>{{ athlete_list|length }}<a>
<a href='#tag-else' class='djula-tag'>{% else %}<a>
No athletes.
<a href='#tag-endif' class='djula-tag'>{% endif %}<a>
In the above, if `athlete_list' is not empty, the number of athletes will be displayed
by the <a href='#variables' class='djula-tag'>{{ athlete_list|length }}<a> variable.
As you can see, the if tag can take an optional <a href='#tag-else' class='djula-tag'>{% else %}<a> clause that will be
displayed if the test fails.
if tags may use and, or or not to test a number of variables or to negate a given
variable:
<a href='#tag-if' class='djula-tag'>{% if athlete_list and coach_list %}<a>
Both athletes and coaches are available.
<a href='#tag-endif' class='djula-tag'>{% endif %}<a>
<a href='#tag-if' class='djula-tag'>{% if not athlete_list %}<a>
There are no athletes.
<a href='#tag-endif' class='djula-tag'>{% endif %}<a>
<a href='#tag-if' class='djula-tag'>{% if athlete_list or coach_list %}<a>
There are some athletes or some coaches.
<a href='#tag-endif' class='djula-tag'>{% endif %}<a>
<a href='#tag-if' class='djula-tag'>{% if not athlete_list or coach_list %}<a>
There are no athletes or there are some coaches (OK, so
writing English translations of boolean logic sounds
stupid; it's not our fault).
<a href='#tag-endif' class='djula-tag'>{% endif %}<a>
<a href='#tag-if' class='djula-tag'>{% if athlete_list and not coach_list %}<a>
There are some athletes and absolutely no coaches.
<a href='#tag-endif' class='djula-tag'>{% endif %}<a>
if tags don’t allow and and or clauses within the same tag, because the order of logic
would be ambiguous. For example, this is invalid:
<a href='#tag-if' class='djula-tag'>{% if athlete_list and coach_list or cheerleader_list %}<a>
If you need to combine and and or to do advanced logic, just use nested if tags. For
example:
<a href='#tag-if' class='djula-tag'>{% if athlete_list %}<a>
<a href='#tag-if' class='djula-tag'>{% if coach_list or cheerleader_list %}<a>
We have athletes, and either coaches or cheerleaders!
<a href='#tag-endif' class='djula-tag'>{% endif %}<a>
<a href='#tag-endif' class='djula-tag'>{% endif %}<a>
Multiple uses of the same logical operator are fine, as long as you use the same
operator. For example, this is valid:
<a href='#tag-if' class='djula-tag'>{% if athlete_list or coach_list or parent_list or teacher_list %}<a></pre></p>
</li>
<li><a name='tag-ifchanged'></a>
<p><pre><b>IFCHANGED (&REST VARS)</b></pre><p>
<p><pre>Check if a value has changed from the last iteration of a loop.
The 'ifchanged' block tag is used within a loop. It has two possible uses.
Checks its own rendered contents against its previous state and only displays the
content if it has changed. For example, this displays a list of days, only displaying
the month if it changes:
<h1>Archive for <a href='#variables' class='djula-tag'>{{ year }}<a></h1>
<a href='#tag-for' class='djula-tag'>{% for date in days %}<a>
<a href='#tag-ifchanged' class='djula-tag'>{% ifchanged %}<a><h3><a href='#variables' class='djula-tag'>{{ date|date:"F" }}<a></h3><a href='#tag-endifchanged' class='djula-tag'>{% endifchanged %}<a>
<a href="<a href='#variables' class='djula-tag'>{{ date|date:"M/d"|lower }}<a>/"><a href='#variables' class='djula-tag'>{{ date|date:"j" }}<a></a>
<a href='#tag-endfor' class='djula-tag'>{% endfor %}<a>
If given a variable, check whether that variable has changed. For example, the
following shows the date every time it changes, but only shows the hour if both the
hour and the date has changed:
<a href='#tag-for' class='djula-tag'>{% for date in days %}<a>
<a href='#tag-ifchanged' class='djula-tag'>{% ifchanged date.date %}<a> <a href='#variables' class='djula-tag'>{{ date.date }}<a> <a href='#tag-endifchanged' class='djula-tag'>{% endifchanged %}<a>
<a href='#tag-ifchanged' class='djula-tag'>{% ifchanged date.hour date.date %}<a>
<a href='#variables' class='djula-tag'>{{ date.hour }}<a>
<a href='#tag-endifchanged' class='djula-tag'>{% endifchanged %}<a>
<a href='#tag-endfor' class='djula-tag'>{% endfor %}<a></pre></p>
</li>
<li><a name='tag-ifequal'></a>
<p><pre><b>IFEQUAL (A B)</b></pre><p>
<p><pre>Output the contents of the block if the two arguments equal each other.
Example:
<a href='#tag-ifequal' class='djula-tag'>{% ifequal user.id comment.user_id %}<a>
...
<a href='#tag-endifequal' class='djula-tag'>{% endifequal %}<a>
As in the <a href='#tag-if' class='djula-tag'>{% if %}<a> tag, an <a href='#tag-else' class='djula-tag'>{% else %}<a> clause is optional.
The arguments can be hard-coded strings, so the following is valid:
<a href='#tag-ifequal' class='djula-tag'>{% ifequal user.username "adrian" %}<a>
...
<a href='#tag-endifequal' class='djula-tag'>{% endifequal %}<a>
It is only possible to compare an argument to template variables or strings. You cannot
check for equality with Lisp objects such as T or NIL. If you need to test if
something is true or false, use the if tag instead.</pre></p>
</li>
<li><a name='tag-ifnotequal'></a>
<p><pre><b>IFNOTEQUAL (A B)</b></pre><p>
<p><pre>Just like <a href='#tag-ifequal' class='djula-tag'>{% ifequal %}<a>, except it tests that the two arguments are not equal.</pre></p>
</li>
<li><a name='tag-include'></a>
<p><pre><b>INCLUDE (TEMPLATE-PATH)</b></pre><p>
<p><pre>Loads a template and renders it with the current context. This is a way of
"including" other templates within a template. The `TEMPLATE-NAME' can either be a
variable or a hard-coded (quoted) string, in double quotes.
This example includes the contents of the template 'foo/bar.html':
<a href='#tag-include' class='djula-tag'>{% include "foo/bar.html" %}<a>
This example includes the contents of the template whose name is contained in the
variable template_name:
<a href='#tag-include' class='djula-tag'>{% include template_name %}<a>
An included template is rendered with the context of the template that’s including it.
This example produces the output "Hello, John":
Context: variable person is set to "john".
Template: <a href='#tag-include' class='djula-tag'>{% include "name_snippet.html" %}<a>
The "name_snippet.html" template:
Hello, <a href='#variables' class='djula-tag'>{{ person }}<a>
See also: <a href='#tag-ssi' class='djula-tag'>{% ssi %}<a>.</pre></p>
<p><pre><b>Different from Django because:</b> If `TEMPLATE-PATH' is a hard-coded string it must use double quotes [not
single-quotes]. Also, `TEMPLATE-PATH' knows about the template directory, so you can
use an absolute path beginning at the base of the template directory not just a
relative path starting at the current template.</pre></p>
</li>
<li><a name='tag-js'></a>
<p><pre><b>JS (SRC)</b> <i><a href='#different-from-django'>New, not in Django</a></i></pre><p>
<p><pre>Makes subsequent occurences of <a href='#tag-emit-js' class='djula-tag'>{% emit-js %}<a> load the external javascript located
at `SRC'
If the tag
<a href='#tag-js' class='djula-tag'>{% js 'http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js' %}<a>
appears in a template then subsequent occurences of the <a href='#tag-emit-js' class='djula-tag'>{% emit-js %}<a> tag will print the
following HTML element:
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js' ></script>
before the HTML of any previous <a href='#tag-js' class='djula-tag'>{% js %}<a> or <a href='#tag-js-script' class='djula-tag'>{% js-script %}<a> tags and after any following
<a href='#tag-js' class='djula-tag'>{% js %}<a> or <a href='#tag-js-script' class='djula-tag'>{% js-script %}<a> tags.
if you need to add other attributes to the <script/> tag just add them after the first
`SRC' argument.
see also <a href='#tag-js-script' class='djula-tag'>{% js-script %}<a>, <a href='#tag-emit-js' class='djula-tag'>{% emit-js %}<a>
</pre></p>
</li>
<li><a name='tag-js-script'></a>
<p><pre><b>JS-SCRIPT</b> <i><a href='#different-from-django'>New, not in Django</a></i></pre><p>
<p><pre>Makes subsequent occurences of <a href='#tag-emit-js' class='djula-tag'>{% emit-js %}<a> run the inline javascript occuring between
<a href='#tag-js-script' class='djula-tag'>{% js-script %}<a> and <a href='#tag-endjs-script' class='djula-tag'>{% endjs-script %}<a>
If the tag
<a href='#tag-js-script' class='djula-tag'>{% js-script %}<a>
new Ajax.Autocompleter('foo-input', 'foo-div', 'http://example.com');
<a href='#tag-endjs-script' class='djula-tag'>{% endjs-script %}<a>
appears in a template then subsequent occurences of the <a href='#tag-emit-js' class='djula-tag'>{% emit-js %}<a> tag will print the
following HTML element:
<script type='text/javascript'>
new Ajax.Autocompleter('foo-input', 'foo-div', 'http://example.com');
</script>
before the HTML of any previous <a href='#tag-js' class='djula-tag'>{% js %}<a> or <a href='#tag-js-script' class='djula-tag'>{% js-script %}<a> tags and after any following
<a href='#tag-js' class='djula-tag'>{% js %}<a> or <a href='#tag-js-script' class='djula-tag'>{% js-script %}<a> tags.
see also <a href='#tag-js' class='djula-tag'>{% js %}<a>, <a href='#tag-emit-js' class='djula-tag'>{% emit-js %}<a>
</pre></p>
</li>
<li><a name='tag-lisp'></a>
<p><pre><b>LISP (SEXP)</b> <i><a href='#different-from-django'>New, not in Django</a></i></pre><p>
<p><pre>reads `SEXP' as Common Lisp code using the "cl-user" package, evaluates it, and
prints the result.
So the tag
<a href='#tag-lisp' class='djula-tag'>{% lisp (+ 4 5) %}<a>
shows up in the browser as
9
note: <a href='#tag-lisp' class='djula-tag'>{% lisp %}<a> tags can be turned off by setting the variable *EVAL-LISP-TAGS*
to NIL</pre></p>
</li>
<li><a name='tag-set-language'></a>
<p><pre><b>SET-LANGUAGE (LANGUAGE-NAME)</b> <i><a href='#different-from-django'>New, not in Django</a></i></pre><p>
<p><pre>After this tag is seen, the current template starts using the language named
`LANGUAGE-NAME'.</pre></p>
</li>
<li><a name='tag-show-language'></a>
<p><pre><b>SHOW-LANGUAGE</b> <i><a href='#different-from-django'>New, not in Django</a></i></pre><p>
<p><pre>prints the name of the language currently being used by the template</pre></p>
</li>
<li><a name='tag-show-table'></a>
<p><pre><b>SHOW-TABLE (TEMPLATE-PATH)</b> <i><a href='#different-from-django'>New, not in Django</a></i></pre><p>
<p><pre>Output the contents of a given table into the page, html-escaping it first.</pre></p>
</li>
<li><a name='tag-ssi'></a>
<p><pre><b>SSI (TEMPLATE-PATH)</b></pre><p>
<p><pre>Output the contents of a given file into the page.
Like a simple "include" tag, <a href='#tag-ssi' class='djula-tag'>{% ssi %}<a> includes the contents of another file — which
must be specified using an absolute path — in the current page:
<a href='#tag-ssi' class='djula-tag'>{% ssi "/home/html/ljworld.com/includes/right_generic.html" %}<a>
If the optional "parsed" parameter is given, the contents of the included file are
evaluated as template code, within the current context:
<a href='#tag-ssi' class='djula-tag'>{% ssi "/home/html/ljworld.com/includes/right_generic.html" parsed %}<a>
Note that if you use <a href='#tag-ssi' class='djula-tag'>{% ssi %}<a>, a programmer will need to set *ALLOWED-INCLUDE-ROOTS*
for you as a security measure.
See also: <a href='#tag-include' class='djula-tag'>{% include %}<a>.</pre></p>
<p><pre><b>Different from Django because:</b> <a href='#tag-ssi' class='djula-tag'>{% ssi %}<a>'s path must be double-quoted to work. Also, Django's ALLOWED_INCLUDE_ROOTS
is called *ALOWED-INCLUDE-ROOTS* and lives in the "djula" package</pre></p>
</li>
<li><a name='tag-templatetag'></a>
<p><pre><b>TEMPLATETAG (ARGUMENT)</b></pre><p>
<p><pre>Output one of the syntax characters used to compose template tags.
Since the template system has no concept of "escaping", to display one of the bits
used in template tags, you must use the <a href='#tag-templatetag' class='djula-tag'>{% templatetag %}<a> tag.
The argument tells which template bit to output:
Argument Outputs
openblock {%
closeblock %}
openvariable <a href='#variables' class='djula-tag'>{{
closevariable }}<a>
openbrace {
closebrace }
opencomment <a href='#comments' class='djula-tag'>{#
closecomment #}<a>
opentranslationvariable <a href='#translation-variables' class='djula-tag'>{_
closetranslationvariable _}<a>
</pre></p>
</li>
<li><a name='tag-translation'></a>
<p><pre><b>TRANSLATION (VARIABLE-NAME LANGUAGE/VALUE-PLIST)</b> <i><a href='#different-from-django'>New, not in Django</a></i></pre><p>
<p><pre><a href='#tag-translation' class='djula-tag'>{% translation %}<a> enables the designer to provide translations without involving
an actual translation table [see <a href='#tag-translation-table' class='djula-tag'>{% translation-table %}<a>]
So if there is a tag
<a href='#tag-translation' class='djula-tag'>{% translation foo english "The Foo" spanish "El Foo" %}<a>
then
<a href='#variables' class='djula-tag'>{{foo}}<a>.
will show up in English as:
The Foo.
and in Spanish as
El Foo.
Note: Although there can be nested tags, filters, comments, etc in translation
tags, there cannot be variables inside <a href='#tag-translation' class='djula-tag'>{% translation %}<a> tags.
see also: <a href='#tag-set-language' class='djula-tag'>{% set-language %}<a>, <a href='#tag-show-language' class='djula-tag'>{% show-language %}<a>, <a href='#tag-translation-table' class='djula-tag'>{% translation-table %}<a></pre></p>
</li>
<li><a name='tag-translation-table'></a>
<p><pre><b>TRANSLATION-TABLE (TEMPLATE-PATH)</b> <i><a href='#different-from-django'>New, not in Django</a></i></pre><p>
<p><pre><a href='#tag-translation-table' class='djula-tag'>{% translation-table %}<a> tags allow the designer to make pages that display
different text when rendered in different languages.
A <a href='#tag-translation' class='djula-tag'>{% translation %}<a> tag makes everything below them in the template aware of the
translations inside the file pointed to be `TEMPLATE-PATH'.
the file pointed to by `TEMPLATE-PATH' should be filled with Lisp lists that start
with the name of a variable [as a lisp keyword] and end with a plist of
language/value pairs.
So if the translation table "inter.XYZ.sexp" contains:
(hello english "Hello" spanish "Hola")
(good-afternoon english "Good afternoon" spanish "Buenas tardes")
then the template
<a href='#tag-translation-table' class='djula-tag'>{% translation-table "/inter.XYZ.sexp" $}<a>
<a href='#translation-variables' class='djula-tag'>{_hello_}<a>, Jill. <a href='#translation-variables' class='djula-tag'>{_good-afternoon_}<a>.
will be rendered in English as:
Hello, Jill. Good afternoon.
and in Spanish as:
Hola, Jill. Buenas tardes.
Note that translations can have nested tags, filters, comments, etc in them.
see also: <a href='#tag-set-language' class='djula-tag'>{% set-language %}<a>, <a href='#tag-show-language' class='djula-tag'>{% show-language %}<a>, <a href='#tag-translation' class='djula-tag'>{% translation %}<a>, and
<a href='#tag-show-table' class='djula-tag'>{% show-table %}<a></pre></p>
</li>
</ul>
<h3><a name='known-filter-reference'></a>Known Filter Reference</h3>
<p>
<ul>
<li><a name='filter-capfirst'></a>
<p><pre><b>CAPFIRST</b> <b>(THING)</b></pre><p>
<p><pre>Capitalizes the first character of the value</pre></p>
</li>
<li><a name='filter-cut'></a>
<p><pre><b>CUT</b> <b>(THING)</b></pre><p>
<p><pre>Removes all values of arg from the given string.
For example:
<a href='#variables' class='djula-tag'>{{ value|cut:" "}}<a>
If value is "String with spaces", the output will be "Stringwithspaces".</pre></p>
</li>
<li><a name='filter-default'></a>
<p><pre><b>DEFAULT</b> <b>(THING DEFAULT)</b></pre><p>
<p><pre>...document me...</pre></p>
<p><b>But is different from Django because:</b> </p>
</li>
<li><a name='filter-force_escape'></a>
<p><pre><b>FORCE_ESCAPE</b> <b>(THING)</b></pre><p>
<p><pre>Applies HTML escaping to a string (see the escape filter for details). This filter is
applied immediately and returns a new, escaped string. This is useful in the rare cases