search

Home  >  Q&A  >  body text

How to use the helper of arttemplate.js?

I learned based on the official chestnuts
But a problem occurred
I want to use helper to register a method
But it always prompts template.helper is not a function
I don’t know if it’s me Is there a problem when calling or is there a problem with the imported js
The code is as follows

<!DOCTYPE html>
<html>
<head lang="zh-cn">
    <meta charset="UTF-8">
    <title>arttemplate</title>
    <script src="template-web.js"></script>
</head>
<body>
    <p id="content3"></p>
    <script id="test3" type="text/html">
            //<p>{{add(1,2)}}</p>
            <p>{{add:'1,2'}}</p>
    </script>
</body>
<script>
    template.helper('add',function(val1,val2){
        return val1 + val2;
    });

    //var data3 = {
        //list: [32,45,47,61,52,41,32,29,44,24,55,19]
    //}
    var html = template('test3');
    document.getElementById('content3').innerHTML = html;
</script>
</html>
三叔三叔2740 days ago843

reply all(2)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-06-12 09:30:25

    Which version are you using? Where did you read the document?

    See the official documentation API: https://aui.github.io/art-tem...

    Indeedthere is nothis method.

    reply
    0
  • 天蓬老师

    天蓬老师2017-06-12 09:30:25

    To summarize the basic calling methods
    Call method 1:
    {{method name parameter 1 parameter 2...parameter n}}
    Call method 2:
    {{method name parameter 1, Parameter 2,...,Parameter n}}
    Call method 3: (|The spaces before and after the symbol cannot be omitted)
    {{Parameter 1 | Method name: Parameter 2, Parameter 3,..., Parameter n}}

    In addition, your annotation method is wrong
    You indicated that your test3 is html and you should use the html annotation method
    which means:
    <!-- <p>...</p> -->
    ------------------------------renew------------------- -------------


    The version number is now 4.10.0. What I write here is the writing method of 3.x

    reply
    0
  • Cancelreply