github.com/keysonZZZ/kmg@v0.0.0-20151121023212-05317bfd7d39/kmgView/kmgGoTpl/README.md (about)

     1  kmg golang template engine
     2  =================
     3  A PHP like template engine write for golang.
     4  
     5  一个像PHP的golang模板引擎.
     6  
     7  当前版本不稳定,随时会产生不向前兼容.
     8  
     9  * 大幅度减少学习成本,你只需要知道,在 <? ?> 里面写golang语句, 在 <?= ?> 里面写需要渲染的golang表达式即可.
    10  * .gotpl 表示普通文本模板,此处不做任何自动转义 .gotplhtml 表示html模板,此处做3种xss的自动转义.
    11  * 报错有文件名和行号.
    12  * 对html的3种xss转义自动支持(kmgXss.H kmxXss.Urlv kmgXss.Jsonv)
    13  
    14  ### example
    15  template file.
    16  ```html
    17  <?
    18  package example
    19  type Input struct{
    20  	Name     string
    21  	Value    string
    22  	ShowName string
    23  	Comment  string
    24  	Need     bool
    25  	ReadOnly bool
    26  	Id       string
    27  }
    28  func tplInputString(config Input)string{
    29  ?>
    30  <div class="form-group has-feedback">
    31      <label class="col-sm-2 control-label"><?=config.ShowName?>
    32      <? if config.Need{ ?>
    33          <span style="color:red">*</span>
    34      <? } ?>
    35  
    36      <div class="col-sm-8">
    37          <input type="text" autocomplete="off" class="form-control"
    38                 <? if config.ReadOnly{ ?>readonly<? } ?>
    39                 name="<?=config.Name?>"
    40          value="<?=config.Value?>"/>
    41          <span style="font-size:12px;color:red">
    42              <? if config.Comment!=""{ ?>
    43                  提示: <?=config.Comment?>
    44              <? } ?>
    45          </span>
    46      </div>
    47  </div>
    48  <? }
    49  ?>
    50  ```
    51  
    52  use the function `kmgGoTpl.MustBuildTplInDir("src/github.com/bronze1man/kmg/kmgView/testFile")` to compile the template in your make file.
    53  
    54  
    55  ### TODO
    56  * 允许在golang的字符串,注释,部分出现语法引擎使用过的关键字(<?= <? ?> func { } import ( ) 等)
    57  * 自动golang类型分析(确定是否直接渲染字符串,慢?)
    58  
    59  ### reference
    60  * 大部分点子来源于 https://github.com/sipin/gorazor