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.

138 lines
3.9 KiB

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