Version: v0.6.1 - Beta.  We welcome contributors & feedback.  THanks!

Page Auto-Functions


Auto-functions are functions that are called automatically when a page loads, if they follow the given naming conventions.

This helps you define entry points for your app in a consistent way.

Return Values 

If an auto-function returns a value, the page will do one of the following:

main Auto-Method 

By default, if your page has a main function, it will automatically be called when the page is loaded.

F main() {
        title: 'Hello!',
        body: mainHtml()

template mainHtml() {
    <b>Hello World!</b>

post Auto-Functions 

If the page is being loaded as a POST HTTP request, it will call a post() function if it is present.

This is useful for forms, where a page could be called as either a GET method (default, show the form) or POST (submitted form data).

// URL: /user/edit

// Only runs if this is a `get` request.
F main() {

// Only runs if this is a `post` request.
F post() {
    $email ='email');
    // (update email in database)

    return url'/user';  // redirect

mode- Auto-Functions 

The page will automatically call a F that is prefixed with mode- if there is a param named mode in the request.

The mode name can come from one of two sources:

This can be useful for REST or Ajax endpoints.

//--- File: settings/app.jcon ---

routes: {
    /article/{mode}:  article.tht

//--- File: pages/article.tht ---

// url: `/article/delete`
F modeDelete() {
    // ...
    return { status: 'deleted' };  // JSON response

// url: `/article/add-to-favorites`
F modeAddToFavorites() {
    // ...
    return { status: 'added' };

See Also