5 <title>CodeMirror: Smarty mode</title>
6 <link rel="stylesheet" href="../../lib/codemirror.css">
7 <script src="../../lib/codemirror.js"></script>
8 <script src="smarty.js"></script>
9 <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
10 <link rel="stylesheet" href="../../doc/docs.css">
13 <h1>CodeMirror: Smarty mode</h1>
15 <h3>Default settings (Smarty 2, <b>{</b> and <b>}</b> delimiters)</h3>
16 <form><textarea id="code" name="code">
17 {extends file="parent.tpl"}
18 {include file="template.tpl"}
20 {* some example Smarty content *}
21 {if isset($name) && $name == 'Blog'}
23 {$integer = 451}, {$array[] = "a"}, {$stringvar = "string"}
24 {assign var='bob' value=$var.prop}
25 {elseif $name == $foo}
26 {function name=menu level=0}
27 {foreach $data as $entry}
30 {menu data=$entry level=$level+1}
36 {/if}</textarea></form>
39 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
47 <h3>Smarty 2, custom delimiters</h3>
48 <form><textarea id="code2" name="code2">
49 {--extends file="parent.tpl"--}
50 {--include file="template.tpl"--}
52 {--* some example Smarty content *--}
53 {--if isset($name) && $name == 'Blog'--}
55 {--$integer = 451--}, {--$array[] = "a"--}, {--$stringvar = "string"--}
56 {--assign var='bob' value=$var.prop--}
57 {--elseif $name == $foo--}
58 {--function name=menu level=0--}
59 {--foreach $data as $entry--}
60 {--if is_array($entry)--}
62 {--menu data=$entry level=$level+1--}
68 {--/if--}</textarea></form>
71 var editor = CodeMirror.fromTextArea(document.getElementById("code2"), {
85 <textarea id="code3" name="code3">
86 Nested tags {$foo={counter one=1 two={inception}}+3} are now valid in Smarty 3.
90 console.log("Smarty 3 permits single curly braces followed by whitespace to NOT slip into Smarty mode.");
94 {assign var=foo value=[1,2,3]}
95 {assign var=foo value=['y'=>'yellow','b'=>'blue']}
96 {assign var=foo value=[1,[9,8],3]}
98 {$foo=$bar+2} {* a comment *}
99 {$foo.bar=1} {* another comment *}
100 {$foo = myfunct(($x+$y)*3)}
101 {$foo = strlen($bar)}
102 {$foo.bar.baz=1}, {$foo[]=1}
104 Smarty "dot" syntax (note: embedded {} are used to address ambiguities):
106 {$foo.a.b.c} => $foo['a']['b']['c']
107 {$foo.a.$b.c} => $foo['a'][$b]['c']
108 {$foo.a.{$b+4}.c} => $foo['a'][$b+4]['c']
109 {$foo.a.{$b.c}} => $foo['a'][$b['c']]
111 {$object->method1($x)->method2($y)}</textarea>
114 var editor = CodeMirror.fromTextArea(document.getElementById("code3"), {
122 <p>A plain text/Smarty version 2 or 3 mode, which allows for custom delimiter tags.</p>
124 <p><strong>MIME types defined:</strong> <code>text/x-smarty</code></p>