The ebl_buildJs plugin generates <script> tags for JavaScript files located in a specific theme’s directory in a Textpattern CMS installation. It supports bulk loading, single-file loading, exclusions, and natural sorting of files for easy integration of JavaScript assets.
To use the plugin, insert the following tag in your Textpattern template or page:
<txp:ebl_buildJs theme="theme_name" directory="js_directory" />
theme
(Required):theme="my_theme"
directory
(Optional):directory="scripts"
name
(Optional):.js
extension (e.g., name="script1"
).name="script1"
exclude
(Optional):.js
extension) to exclude from bulk loading.name
attribute is used.exclude="script1,script2"
To load all JavaScript files in a theme’s js
directory except for script1.js
:
<txp:ebl_buildJs theme="my_theme" directory="js" exclude="script1" />
Directory structure:
my_theme/ js/ script1.js script2.js script3.js
Output:
<script src="https://your-site.com/skins/my_theme/js/script2.js" defer></script> <script src="https://your-site.com/skins/my_theme/js/script3.js" defer></script>
To load only script1.js
from the js
directory:
<txp:ebl_buildJs theme="my_theme" directory="js" name="script1" />
Output:
<script src="https://your-site.com/skins/my_theme/js/script1.js" defer></script>
Files are naturally sorted (e.g., numerically or alphabetically) before being loaded. For example, files named 01-file.js
, 02-file.js
, and 10-file.js
will load in numerical order.
theme
attribute is missing.<!-- Error: No theme name specified -->
<!-- Error: Specified directory does not exist: [full_path_to_directory] -->
.js
files.<!-- Error: No JS files found in directory: [full_path_to_directory] -->
name
attribute specifies a file that does not exist in the directory.<!-- Error: Specified file does not exist: [file_name.js] -->
name
attribute.exclude
attribute.