You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.6 KiB

3 years ago
  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="smarty.js"></script>
  8. <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
  9. <div id=nav>
  10. <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
  11. <ul>
  12. <li><a href="../../index.html">Home</a>
  13. <li><a href="../../doc/manual.html">Manual</a>
  14. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  15. </ul>
  16. <ul>
  17. <li><a href="../index.html">Language modes</a>
  18. <li><a class=active href="#">Smarty</a>
  19. </ul>
  20. </div>
  21. <article>
  22. <h2>Smarty mode</h2>
  23. <form><textarea id="code" name="code">
  24. {extends file="parent.tpl"}
  25. {include file="template.tpl"}
  26. {* some example Smarty content *}
  27. {if isset($name) && $name == 'Blog'}
  28. This is a {$var}.
  29. {$integer = 451}, {$array[] = "a"}, {$stringvar = "string"}
  30. {assign var='bob' value=$var.prop}
  31. {elseif $name == $foo}
  32. {function name=menu level=0}
  33. {foreach $data as $entry}
  34. {if is_array($entry)}
  35. - {$entry@key}
  36. {menu data=$entry level=$level+1}
  37. {else}
  38. {$entry}
  39. {/if}
  40. {/foreach}
  41. {/function}
  42. {/if}</textarea></form>
  43. <script>
  44. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  45. lineNumbers: true,
  46. mode: "smarty"
  47. });
  48. </script>
  49. <br />
  50. <h3>Smarty 2, custom delimiters</h3>
  51. <form><textarea id="code2" name="code2">
  52. {--extends file="parent.tpl"--}
  53. {--include file="template.tpl"--}
  54. {--* some example Smarty content *--}
  55. {--if isset($name) && $name == 'Blog'--}
  56. This is a {--$var--}.
  57. {--$integer = 451--}, {--$array[] = "a"--}, {--$stringvar = "string"--}
  58. {--assign var='bob' value=$var.prop--}
  59. {--elseif $name == $foo--}
  60. {--function name=menu level=0--}
  61. {--foreach $data as $entry--}
  62. {--if is_array($entry)--}
  63. - {--$entry@key--}
  64. {--menu data=$entry level=$level+1--}
  65. {--else--}
  66. {--$entry--}
  67. {--/if--}
  68. {--/foreach--}
  69. {--/function--}
  70. {--/if--}</textarea></form>
  71. <script>
  72. var editor = CodeMirror.fromTextArea(document.getElementById("code2"), {
  73. lineNumbers: true,
  74. mode: {
  75. name: "smarty",
  76. leftDelimiter: "{--",
  77. rightDelimiter: "--}"
  78. }
  79. });
  80. </script>
  81. <br />
  82. <h3>Smarty 3</h3>
  83. <textarea id="code3" name="code3">
  84. Nested tags {$foo={counter one=1 two={inception}}+3} are now valid in Smarty 3.
  85. <script>
  86. function test() {
  87. console.log("Smarty 3 permits single curly braces followed by whitespace to NOT slip into Smarty mode.");
  88. }
  89. </script>
  90. {assign var=foo value=[1,2,3]}
  91. {assign var=foo value=['y'=>'yellow','b'=>'blue']}
  92. {assign var=foo value=[1,[9,8],3]}
  93. {$foo=$bar+2} {* a comment *}
  94. {$foo.bar=1} {* another comment *}
  95. {$foo = myfunct(($x+$y)*3)}
  96. {$foo = strlen($bar)}
  97. {$foo.bar.baz=1}, {$foo[]=1}
  98. Smarty "dot" syntax (note: embedded {} are used to address ambiguities):
  99. {$foo.a.b.c} => $foo['a']['b']['c']
  100. {$foo.a.$b.c} => $foo['a'][$b]['c']
  101. {$foo.a.{$b+4}.c} => $foo['a'][$b+4]['c']
  102. {$foo.a.{$b.c}} => $foo['a'][$b['c']]
  103. {$object->method1($x)->method2($y)}</textarea>
  104. <script>
  105. var editor = CodeMirror.fromTextArea(document.getElementById("code3"), {
  106. lineNumbers: true,
  107. mode: "smarty",
  108. smartyVersion: 3
  109. });
  110. </script>
  111. <p>A plain text/Smarty version 2 or 3 mode, which allows for custom delimiter tags.</p>
  112. <p><strong>MIME types defined:</strong> <code>text/x-smarty</code></p>
  113. </article>