scripts/CodeMirror/mode/smarty/index.html (view raw)
1<!doctype html>
2
3<title>CodeMirror: Smarty mode</title>
4<meta charset="utf-8"/>
5<link rel=stylesheet href="../../doc/docs.css">
6
7<link rel="stylesheet" href="../../lib/codemirror.css">
8<script src="../../lib/codemirror.js"></script>
9<script src="../xml/xml.js"></script>
10<script src="smarty.js"></script>
11<style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
12<div id=nav>
13 <a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
14
15 <ul>
16 <li><a href="../../index.html">Home</a>
17 <li><a href="../../doc/manual.html">Manual</a>
18 <li><a href="https://github.com/codemirror/codemirror">Code</a>
19 </ul>
20 <ul>
21 <li><a href="../index.html">Language modes</a>
22 <li><a class=active href="#">Smarty</a>
23 </ul>
24</div>
25
26<article>
27<h2>Smarty mode</h2>
28<form><textarea id="code" name="code">
29{extends file="parent.tpl"}
30{include file="template.tpl"}
31
32{* some example Smarty content *}
33{if isset($name) && $name == 'Blog'}
34 This is a {$var}.
35 {$integer = 451}, {$array[] = "a"}, {$stringvar = "string"}
36 {assign var='bob' value=$var.prop}
37{elseif $name == $foo}
38 {function name=menu level=0}
39 {foreach $data as $entry}
40 {if is_array($entry)}
41 - {$entry@key}
42 {menu data=$entry level=$level+1}
43 {else}
44 {$entry}
45 {/if}
46 {/foreach}
47 {/function}
48{/if}</textarea></form>
49
50<p>Mode for Smarty version 2 or 3, which allows for custom delimiter tags.</p>
51
52<p>Several configuration parameters are supported:</p>
53
54<ul>
55 <li><code>leftDelimiter</code> and <code>rightDelimiter</code>,
56 which should be strings that determine where the Smarty syntax
57 starts and ends.</li>
58 <li><code>version</code>, which should be 2 or 3.</li>
59 <li><code>baseMode</code>, which can be a mode spec
60 like <code>"text/html"</code> to set a different background mode.</li>
61</ul>
62
63<p><strong>MIME types defined:</strong> <code>text/x-smarty</code></p>
64
65<h3>Smarty 2, custom delimiters</h3>
66
67<form><textarea id="code2" name="code2">
68{--extends file="parent.tpl"--}
69{--include file="template.tpl"--}
70
71{--* some example Smarty content *--}
72{--if isset($name) && $name == 'Blog'--}
73 This is a {--$var--}.
74 {--$integer = 451--}, {--$array[] = "a"--}, {--$stringvar = "string"--}
75 {--assign var='bob' value=$var.prop--}
76{--elseif $name == $foo--}
77 {--function name=menu level=0--}
78 {--foreach $data as $entry--}
79 {--if is_array($entry)--}
80 - {--$entry@key--}
81 {--menu data=$entry level=$level+1--}
82 {--else--}
83 {--$entry--}
84 {--/if--}
85 {--/foreach--}
86 {--/function--}
87{--/if--}</textarea></form>
88
89<h3>Smarty 3</h3>
90
91<textarea id="code3" name="code3">
92Nested tags {$foo={counter one=1 two={inception}}+3} are now valid in Smarty 3.
93
94<script>
95function test() {
96 console.log("Smarty 3 permits single curly braces followed by whitespace to NOT slip into Smarty mode.");
97}
98</script>
99
100{assign var=foo value=[1,2,3]}
101{assign var=foo value=['y'=>'yellow','b'=>'blue']}
102{assign var=foo value=[1,[9,8],3]}
103
104{$foo=$bar+2} {* a comment *}
105{$foo.bar=1} {* another comment *}
106{$foo = myfunct(($x+$y)*3)}
107{$foo = strlen($bar)}
108{$foo.bar.baz=1}, {$foo[]=1}
109
110Smarty "dot" syntax (note: embedded {} are used to address ambiguities):
111
112{$foo.a.b.c} => $foo['a']['b']['c']
113{$foo.a.$b.c} => $foo['a'][$b]['c']
114{$foo.a.{$b+4}.c} => $foo['a'][$b+4]['c']
115{$foo.a.{$b.c}} => $foo['a'][$b['c']]
116
117{$object->method1($x)->method2($y)}</textarea>
118
119<script>
120var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
121 lineNumbers: true,
122 mode: "smarty"
123});
124var editor = CodeMirror.fromTextArea(document.getElementById("code2"), {
125 lineNumbers: true,
126 mode: {
127 name: "smarty",
128 leftDelimiter: "{--",
129 rightDelimiter: "--}"
130 }
131});
132var editor = CodeMirror.fromTextArea(document.getElementById("code3"), {
133 lineNumbers: true,
134 mode: {name: "smarty", version: 3, baseMode: "text/html"}
135});
136</script>
137
138</article>