About JavaScript
JavaScript is one of the most popular programming languages in use today. It's been around since 1995, but its popularity really took off in the early 2000s with the rise of dynamic web applications. Today, it's a requirement for anyone who wants to create an app or website that runs on a browser.
JavaScript in Docly™
Docly™ uses JavaScript to generate HTML, CSS, TXT etc files server side with #JS, and also allows you to create a JSON WEB API with .JS files from the API folder.
#JS is the syntax used by HashJS — Docly's own JavaScript engine for data binding and server-side rendering, written in .NET. See hashjs.org for the full HashJS reference.
The Docly™ files #/API/*.JS and *.HASH files all use JavaScript syntax. They just run on the server.
Docly™ makes its internal functions available in JavaScript through the "docly" object. There you can find a library of functions to retrieve and store data in Docly™ from your JavaScript code.
See #JS example below:
#{
let files = docly.getFiles("/");
for(let file of files) {
}#
<a href="#file.Url#">#file.filename#</a>
#}# Two modes: templates and API
HashJS runs code in one of two modes:
Mode | Where | What it means |
|---|---|---|
Template mode (compatibility mode) | .hash pages and schema display templates (such as #/<Schema>.hash) | Standard JavaScript plus Docly's older template syntax: bracket blocks ( |
API mode (standard JavaScript) | Files in #/API, services, and modules they import | The older template syntax is not available. The legacy helpers exist only with the docly. prefix (for example docly.cint()), so names such as push, trim and replace keep their standard meaning, and |
Template mode can be turned off for a whole site with "hashjs": { "compatibilityMode": false } in #/site.json, or for a single schema template with the Modern syntax option in the schema editor. #/API files always run in API mode. Code inside ${…} in a template literal is always standard JavaScript.
The legacy helpers are described in Legacy template helpers. New code should use standard JavaScript.
Differences from standard JavaScript
HashJS is not a browser and not Node.js: there is no DOM (apart from DOMParser), no setTimeout and no require() or npm packages. Some built-in functions are missing, and a few behave differently. See Differences from standard JavaScript before you port code from elsewhere.
Why JavaScript?
JavaScript's popularity has grown exponentially over the years—it's used on over 80% of websites and is now even being used for app development on mobile devices. There's a lot of excitement about where JavaScript will go next!
JavaScript is a programming language that has been around for more than 20 years. It is now the most widely used language on the internet.
It's easy to learn and use, and it's also powerful enough to build complex applications.
JavaScript will continue to be one of the most important languages for web development for years to come!
Learn more
Read more about JavaScript at MDN Web Docs. Not everything described there is available in HashJS — check Differences from standard JavaScript.
To use these functions in an API endpoint, see JS files in the API folder in this section and API & Services. For scheduled jobs and events, see Services - scheduling and events.