ebl_buildJs Plugin Help

Plugin Name: ebl_buildJs

Description:

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.

Usage:

To use the plugin, insert the following tag in your Textpattern template or page:

<txp:ebl_buildJs theme="theme_name" directory="js_directory" />

Attributes:

theme (Required):

directory (Optional):

name (Optional):

exclude (Optional):

Examples:

Example 1: Bulk Loading with Exclusions

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>

Example 2: Load a Single File

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>

Example 3: Sorting Files

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.

Error Handling:

Common Errors:

Installation:

  1. Copy the plugin code into the Textpattern Plugins interface.
  2. Install and enable the plugin.

Changelog:

Version 1.2:

Version 1.1: