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



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


Hello World in Hanjst
Source code


"$" 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" 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}

    {include content="$pagefooter"}