Custom Modules
You can create your own modules in which to organize your functions and make them accessible from any page in your app.
Each module is a .tht
file in the modules
folder.
Module names are always UpperCamelCase.
// --- file: modules/MyModule.tht --- F sayHello($userName) { print('Hello, ' ~ $userName ~ '!'); }
To call a function in a module, use dot .
notation.
// --- file: pages/myPage.tht --- MyModule.sayHello('Taylor'); //= 'Hello, Taylor!'
Modules in the root modules
folder will be automatically included when they are used.
Modules in sub-folders need to be pulled in via import
before they are used.
// pull in file 'modules/styles/Cubism.tht' import('styles/Cubism'); Cubism.getArtists(); //= ['Picasso', 'Braque', 'Gris']
Module Variables
You can assign variables directly to a module.
These act as a namespaced global variable, accessible anywhere within your app.
// --- file: modules/App.tht --- App.contactEmail = 'hello@website.com'; // --- file: pages/home.tht --- $contact = 'Email: ' ~ App.contactEmail;