File Helper

From Onix OS Wiki
Jump to: navigation, search

The renderf() function is used to combine and render files with parameters. It’s simple to use. Returns the result as a string.

Definition

renderf(filename, ...data hash)

The file is "{{.somedefinition }}" by automatically finding the blocks in two brackets, periods, and two brackets, it automatically prints the definitions in the hash that you sent in the second parameter to the file, allowing you to intercept the variables on the file.

Example

def filerender = (renderf(
   "test.html", 
   { 
       "hello": "World", 
       "title": "Hello Example" 
   }
))
show(filerender)

Input File:

<html>
    <head>
        <title>{{.title}}!</title>
    </head>
    <body>
        <h1>{{.hello}}!</h1>
    </body>
</html>

Result:

<html>
    <head>
        <title>Hello Example!</title>
    </head>
    <body>
        <h1>World!</h1>
    </body>
</html>

In the example, we created a new file by printing some variables to the file exported with input. In this way, you can do the file rendering process. It works like a simple template engine.