⏳ Hanjst Loading... 汉吉斯特加载中...
↻ Reload / 重新加载 ...
Hanjst {include file="$pageheader"} {include file="$model"} {$i=Math.random()} {var $jstr='this is a j string'}

....

Hanjst 汉吉斯特 特征/Features


{foreach $newscontentlist as $page} {foreachelse} {/foreach}

....

Hello World in Hanjst
Source code

Hanjst 汉吉斯特 样例/Demo


"$" is a speical and default tag served as a prefix marker for a variable in Hanjst.

Try to call a func named 'aFunc' and display its return:
{$aFunc($i)}

"aFunc" is an user-defined function with JavaScript.
"$aFunc($i)" is to call aFunc and display its return value.

Similarly, "$alist[$i]" or "$alist[$i][$j]" is to display an element with $i as its key in a hash or array object.

Call a built-in func:
{$jstr.substring(0, 12)}
"substring" is a built-in function for JavaScript.
"jstr" is a variable from server response, which will be accessed via $jstr.

"$jstr" is to display the variable "jstr".
"$jstr.substring(0, 12) is to shorten the string for first 12 bytes and/or chars, then display the modified $jstr.

Give random numbers with while: {while $i<5}
  • line {$i}
  • {$i++} {whileelse}
  • Out of While.
  • {/while}
    ....

    2nd, try to list an associative list: {for var $k in $userlist}

  • Id:{$userlist[$k]['id']}, Name:{$userlist[$k]['name']}
  • {forelse}
  • No more User Data.
  • {/for}

    3rd, try to list an associative list: {foreach $userlist as $k}
  • {$k} Id:{$userlist[$k]['id']}, Name:{$userlist[$k]['name']}
  • {/foreach}

    Try to branch-if-else: {$i=Math.random()} {if $i < 0.3}

  • {$i} is lt 0.3
  • {else if $i<0.5 }
  • {$i} is lt 0.5
  • {else}
  • {$i} is gt 0.5
  • {/if}


    Try literal:
    {literal} {if $user['feedback'] == 2} {$user['age']} {/if} {/literal}

    This is A SPAN with embedded Tpl sentence.
    This is a name. This is a name, 2nd.
    This is a span, 2nd.


    Due to limitations of embedded tags in an HTML element,
    we introduce "lt" as less than (<) , "gt" as greater than(>) and "eq" as equal(=).


    Hanjst 汉吉斯特 在线资源/Online Resources


    Hanjst @ Github
    Hanjst Document and API 汉吉斯特在线文档
    Hanjst Blog 汉吉斯特博客文档

    本页样例可以通过查看 HTML 代码进行翻阅.

    {$num=123.456} 格式化整数: {$num} --> {$parseInt($num)}

    新闻列表:
    {$newsList=[]} {$newsList[0]=new Object()} {$newsList[0]['id']=12} {$newsList[0]['title']='News-Title-12'} {$newsList[1]=new Object()} {$newsList[1]['id']=34} {$newsList[1]['title']='News-Title-34'}

    {$title='Hello Wordl!'} {$titleLength=$title.length}

    {if $titleLength > 50} {$titleLength} is greater than 50! {else if $titleLength > 10} {$titleLength} is greater than 10! {else} {$titleLength} is less than 10! {/if}

    {$strArr2=Object.values($strArr)} Position of 1-b in {"0":"0-a", "1":"1-b"}: [{$strArr2.indexOf("1-b")}]
    Set undefined $aaBbList['a'] to empty:[{$aaBbList['a']}]

    $i: {$i} , $i*2: {=$i*2}


    Hanjst 汉吉斯特 更新记录/Update History


    {literal} * @Since July 07, 2016, refactor on Oct 10, 2018
    * Nov 24, 2018, +include with scripts
    * Dec 02, 2018, +variables, +functions
    * Dec 04, 2018, +tpl2code string to array, +foreach
    * Dec 08, 2018, +else if, +embedded tpl in <>
    * Dec 16, 2018, +literal
    * Jan 01, 2019, +foreachelse, forelse, whileelse
    * Fri Jan 4 03:59:42 UTC 2019, +remedyMemoLine
    * Fri Jan 11 13:48:28 UTC 2019, +codes refine
    * Tue Jan 15 11:53:30 UTC 2019, remove html comments, imprvs with appendScript
    * Mon Feb 11 06:18:18 UTC 2019, +callRender
    * 13:54 Friday, April 19, 2019, + check for undefined $xxx
    * 12:48 Saturday, April 27, 2019, + readable error reporting for template erros
    * 19:19 Sunday, May 19, 2019, + renderTemplateRecurse for deep-in include files.
    * 18:44 Friday, May 31, 2019, + allow limited support for variables in xxxelse scope, bugfix for includeScript.
    * 07:58 6/2/2019, + imprvs with _appendScript to appendScript for async call.
    * 16:31 Wednesday, June 5, 2019, + imprvs with parentNode=BODY
    * 19:18 Monday, June 10, 2019, + bugfix for asyncScripts.
    * 22:29 Thursday, June 13, 2019, + loadingLayer. "<div id="Hanjstloading" style="width: 100%; height: 100%; z-index: 99;"> Xxxx Loading... 加载中... </div>" .
    * 21:36 Thursday, June 20, 2019, + warning for MSIE browsers.
    * Sun Nov 24 11:50:36 CST 2019, + undefined exceptions.
    * 10:12 Monday, December 2, 2019, + time_stamp.
    * 10:34 Friday, April 10, 2020, + func showImageAsync
    * 17:49 Wednesday, May 20, 2020, + _enSafeExpr.
    * 09:52 Thursday, June 4, 2020, + import jsonDataId with script.
    * 11:42 6/11/2020, + {=$i+2} support.
    * 21:42 2020-09-01, imprvs for regExp for remedyMemoLine.
    * 09:08 2021-03-17, imprvs for debug in mobile browsers, +support for if conditionExpr
    * 17:09 2021-04-26, + _enSafeExprAsCondition .
    * 21:32 2021-05-19, bugfix for remedyMemoLine .
    * 12:31 2021-05-21, bugfix for & .
    * 09:04 2021-06-07, add more _enSafeExpr .
    * 21:51 2021-06-29, +comment: use Firefox to figure out exact error lineNumber and columnNumber in tpl2code in new Function
    * 21:55 2021-11-11, imprvs for remedyMemoLine
    * 11:37 2022-01-13, bugfix for remedyMemoLine, v2.7
    * 08:09 2022-06-04, imprvs for delay more time for async scripts, v2.8
    * 22:14 2022-06-07, +asyncScripti for async include scripts embedded, v2.9 {/literal}

    {include content="$pagefooter"}