Subversion-Projekte lars-tiefland.ci

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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