diff --git a/documentation/functions/global/require.md b/documentation/functions/global/require.md index afe45c66e..d7b1a9289 100644 --- a/documentation/functions/global/require.md +++ b/documentation/functions/global/require.md @@ -19,17 +19,18 @@ the currently-loading file (which may not be the file where the is interpreted relative to the program's working directory at the time of the call. +{% code title="dnsconfig.js" %} ```javascript -// dnsconfig.js require('kubernetes/clusters.js'); D("mydomain.net", REG, PROVIDER, IncludeKubernetes() ); ``` +{% endcode %} +{% code title="kubernetes/clusters.js" %} ```javascript -// kubernetes/clusters.js require('./clusters/prod.js'); require('./clusters/dev.js'); @@ -37,29 +38,32 @@ function IncludeKubernetes() { return [includeK8Sprod(), includeK8Sdev()]; } ``` +{% endcode %} +{% code title="kubernetes/clusters/prod.js" %} ```javascript -// kubernetes/clusters/prod.js function includeK8Sprod() { return [ // ... ]; } ``` +{% endcode %} +{% code title="kubernetes/clusters/dev.js" %} ```javascript -// kubernetes/clusters/dev.js function includeK8Sdev() { return [ // ... ]; } ``` +{% endcode %} You can also use it to require JSON files and initialize variables with it: +{% code title="dnsconfig.js" %} ```javascript -// dnsconfig.js var domains = require('./domain-ip-map.json') for (var domain in domains) { @@ -68,14 +72,16 @@ for (var domain in domains) { ); } ``` +{% endcode %} +{% code title="domain-ip-map.json" %} ```javascript -// domain-ip-map.json { "mydomain.net": "1.1.1.1", "myotherdomain.org": "5.5.5.5" } ``` +{% endcode %} # Future diff --git a/documentation/functions/global/require_glob.md b/documentation/functions/global/require_glob.md index 808699fd6..bc83373e1 100644 --- a/documentation/functions/global/require_glob.md +++ b/documentation/functions/global/require_glob.md @@ -30,17 +30,17 @@ require_glob("./domains/", false); One more important thing to note: `require_glob()` is as smart as `require()` is. It loads files always relative to the JavaScript file where it's being executed in. Let's go with an example, as it describes it better: -`dnscontrol.js`: - +{% code title="dnsconfig.js" %} ```javascript require("domains/index.js"); ``` +{% endcode %} -`domains/index.js`: - +{% code title="domains/index.js" %} ```javascript require_glob("./user1/"); ``` +{% endcode %} This will now load files being present underneath `./domains/user1/` and **NOT** at below `./domains/`, as `require_glob()` is called in the subfolder `domains/`.