Skip to content

Commit 5e9aa59

Browse files
committed
improve recipes
1 parent 7886fcf commit 5e9aa59

14 files changed

+314
-463
lines changed

docs/recipes/exception-cause.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Lucee 6.1 improves its support for exception causes, providing better debugging
2626

2727
## Tag Attribute cause
2828

29-
The `<cfthrow>` tag now includes a new attribute, `cause`, which allows you to add a cause to a newly created exception.
29+
The `<cfthrow>` tag now includes a `cause` attribute to chain exceptions:
3030

3131
```run
3232
<cfscript>
@@ -45,11 +45,11 @@ catch(ex) {
4545
</cfscript>
4646
```
4747

48-
Thanks to this enhancement, you get not only the tag context and Java stack trace from the top-level exception, but also the same information for the "cause" exception.
48+
This gives you the tag context and Java stack trace from both the top-level exception and its cause.
4949

5050
## Parent Thread Context
5151

52-
When you throw an exception from a child thread, for example, a `cfhttp` call executed in parallel or an exception inside the `cfthread` tag, you can now see the stack trace from where that thread was started. Previously, you only saw the stack trace within the child thread. With Lucee 6.1, you also get the information from the parent thread as the cause. Consider the following example:
52+
Exceptions from child threads (parallel `cfhttp`, `cfthread`) now include the parent thread's stack trace as the cause - previously you only saw the child thread's stack trace:
5353

5454
```run
5555
<cfscript>
@@ -62,4 +62,4 @@ dump(cfthread["testexception"].error.cause.Message);
6262
</cfscript>
6363
```
6464

65-
The error not only includes the exception information from within the cfthread tag but also provides information from outside, making debugging much easier as you can see where the tag was called from.
65+
The error includes both the exception from within `cfthread` and where it was called from, making debugging much easier.

docs/recipes/extension-installation.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@
2323

2424
# Extension Installation
2525

26-
In Lucee, there are multiple ways to install an extension. This recipe will show you all the possibilities along with their pros and cons.
27-
28-
The standard Lucee jar, (known as the far jar) bundles a number of common extensions (pdf, image etc).
29-
30-
If you want to control which extensions are installed, use Lucee Light (core and admin) or Lucee Zero (core only).
26+
Multiple ways to install extensions in Lucee. The standard jar bundles common extensions (pdf, image etc) - use Lucee Light or Zero for more control.
3127

3228
## Lucee Administrator
3329

@@ -188,14 +184,3 @@ java -Dlucee.extensions="99A4EF8D-F2FD-40C8-8FB8C2E67A4EEEB6;name=MSSQL;version=
188184
## Logging and Troubleshooting
189185

190186
If you encounter issues while installing extensions, you can check the log at `{lucee-installation}/lucee-server/context/logs/deploy.log` not only for any errors reported but also to see what actions were performed. This log is by default set to info level and should contain all details about the installation process.
191-
192-
## Conclusion
193-
194-
Lucee offers several methods to install extensions, each with its own advantages and disadvantages. Choose the method that best fits your deployment and management workflow:
195-
196-
- **Lucee Administrator**: Best for manual, ad-hoc installations.
197-
- **`deploy` Directory**: Good for automated deployments with script support.
198-
- **`.CFConfig.json` Configuration**: Ideal for managing configurations and extensions together.
199-
- **Environment Variable / System Property**: Suitable for modern deployment environments like Docker and cloud services.
200-
201-
By understanding the pros and cons of each method, you can effectively manage Lucee extensions in your environment.

docs/recipes/externalizing-strings.md

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
}
1717
-->
1818

19-
# Externalize strings
19+
# Externalize Strings
2020

21-
Externalize strings from generated class files to separate files. This method is used to reduce the memory of the static contents for templates. We explain this method with a simple example below:
21+
When Lucee compiles a `.cfm` file, all the static HTML and strings get embedded directly in the Java class file. For pages with lots of static content (like email templates or HTML-heavy pages), this bloats the class files and wastes memory - those strings stay loaded even when not needed.
2222

23-
**Example:**
24-
25-
//index.cfm
23+
Externalizing strings moves this static content to separate text files. The class file shrinks, and strings only load on demand when the page actually runs.
2624

2725
```lucee
26+
<!--- index.cfm - mostly static HTML with a bit of CFML --->
2827
<cfset year = 1960>
2928
<html>
3029
<body>
@@ -38,21 +37,12 @@ Externalize strings from generated class files to separate files. This method is
3837
</html>
3938
```
4039

41-
1. Here the Index.cfm file contains a lot of strings (static contents), but there is no functionality. The file just gives a cfoutput with year. The variable string 'year' is already declared by using in top of the Index.cfm page.
42-
43-
2. Execute the CFM page in a browser. A class file is created in the `webapps/ROOT/WEB-INF/lucee/cfclasses/` directory while the CFM file is executed. The run time compiler compiles that file to load the Java bytecode and execute it.
44-
45-
3. Right click the class file. Then see `Get info`. For example, in my class file there is 8Kb size on the disk. In Lucee, the CFM file with its strings was also loaded. So a lot of memory could be occupied just by string loading the bytecode. To avoid this problem, the Lucee admin has the following solution:
46-
47-
- Lucee admin --> Language/compiler --> Externalize strings
48-
- This `Externalize strings` setting has four options. Select any one option to test. We selected the fourth option (externalize strings larger than 10 characters).
49-
- Again run the CFM page in a browser. The class file is created with lower memory size than the original 8Kb on disk.
50-
- In addition, it created a text file too. The text file contains the strings from the CFM page. The cfoutput with year is simply not there. The byte code will crop the piece of cfoutput content from the CFM file.
51-
52-
So, the string 'year' is no longer in memory. When the bytecode is called, it loads the string into memory. The memory is not occupied forever and this reduces the footprint of our application.
40+
Without externalization, all that HTML lives in the class file. With it enabled, only the CFML logic stays in the class.
5341

54-
## Footnotes
42+
Configure via **Lucee Admin > Language/compiler > Externalize strings**:
5543

56-
Here you can see the above details in video
44+
- Strings are moved to separate text files
45+
- Class file size decreases
46+
- Strings load on demand instead of staying in memory
5747

58-
[Externalize strings](https://youtu.be/AUcsHkVFXHE)
48+
Video: [Externalize strings](https://youtu.be/AUcsHkVFXHE)

docs/recipes/file-extensions.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
# File Extensions
2121

22-
Lucee supports several file extensions for different types of templates and components. The most common extensions are `.cfm`, `.cfc`, `.cfml`, and `.cfs`. Each serves a specific purpose in CFML development.
22+
Lucee processes several file types, each serving a different purpose in CFML development. Knowing when to use each helps keep your code organized.
2323

2424
## .cfm
2525

26-
The `.cfm` extension is used for CFML templates. These files contain CFML code that is processed by the server to generate dynamic web pages.
26+
The standard CFML template extension. These files mix CFML tags and HTML to generate dynamic web pages - the workhorse of most CFML applications.
2727

2828
### Example
2929

@@ -44,7 +44,7 @@ The `.cfm` extension is used for CFML templates. These files contain CFML code t
4444

4545
## .cfc
4646

47-
The `.cfc` extension is used for CFML Components (CFCs). These files define reusable components that encapsulate functionality in methods, similar to classes in object-oriented programming.
47+
CFML Components define reusable objects that encapsulate data and behavior - similar to classes in other languages. Use these for your business logic, models, and services.
4848

4949
### Example
5050

@@ -58,11 +58,11 @@ component {
5858

5959
## .cfml
6060

61-
The `.cfml` extension is an alternative to `.cfm` and can be used for CFML templates. It serves the same purpose as `.cfm` but is less commonly used.
61+
Alternative extension for CFML templates - functionally identical to `.cfm`. Some developers prefer the explicit `.cfml` extension, but `.cfm` is far more common.
6262

6363
## .cfs
6464

65-
Since version 6.0, Lucee supports templates with the extension `.cfs`. These templates contain script code, similar to `.js` files in the JavaScript world. This allows you to write direct script code without the need for the `<cfscript>` tag.
65+
Script-only templates introduced in Lucee 6.0. Like `.js` files in the JavaScript world, these contain pure script code without needing `<cfscript>` tags. Great for scripts, utilities, and developers who prefer script syntax over tags.
6666

6767
### Example
6868

docs/recipes/function-listeners.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
# Function Listeners
2525

26-
Lucee 6.1 introduced a new feature called "Function Listeners". This allows you to execute a function (of any kind) in parallel, so you do not have to wait for the result of the execution, similar to using the `cfthread` tag. Function Listeners provide an easy syntax to not only execute a function in parallel but also include support to handle the result by simply adding a listener after the function call. This listener can handle the result or exception of a function.
26+
Execute functions in parallel with a simple listener syntax. Like `cfthread` but cleaner - attach a listener after any function call to handle results or exceptions asynchronously.
2727

2828
## Simple Version
2929

docs/recipes/hidden-gems.md

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,30 @@
1111
"Bracket notation",
1212
"URL form scopes",
1313
"Array format"
14+
],
15+
"categories": [
16+
"language"
1417
]
1518
}
1619
-->
1720

1821
# Hidden Gems
1922

20-
This document explains how to declare variables, function calls with dot and bracket notation, and passing arguments via URL/form scopes as an array. These concepts are explained with simple examples below:
23+
Lesser-known Lucee features that can make your code cleaner and more flexible. These aren't obscure - they're useful patterns that many developers overlook.
2124

22-
## Example 1: Declare Variables
23-
24-
// test.cfc
25+
## Variable Declaration
2526

2627
```luceescript
28+
// test.cfc
2729
component {
2830
function getName() {
2931
return "Susi";
3032
}
3133
}
3234
```
3335

34-
// example1.cfm
35-
3636
```luceescript
37+
// example.cfm
3738
function test() {
3839
var qry;
3940
dump(qry);
@@ -45,50 +46,42 @@ function test() {
4546
test();
4647
```
4748

48-
In the cfm page, we have a test() function with a local variable scope assigned as an empty string `var qry`. When executing this cfm, the qry returns "1". Dumping the `qry` below the var declaration returns an empty string.
49-
50-
## Example 2: Dot and Bracket Notation for Function Calls
49+
Declaring `var qry` creates an empty local variable. The query then populates it.
5150

52-
Lucee allows you to use bracket notation to call a component function.
51+
## Bracket Notation for Function Calls
5352

54-
// example2.cfm
53+
You can call component methods using bracket notation instead of dot notation. This lets you call functions dynamically without the overhead and security concerns of `evaluate()`:
5554

5655
```luceescript
57-
// UDF call via dot notation
56+
// Standard dot notation
5857
test = new Test();
5958
dump( test.getName() );
60-
// Dynamic function name
59+
60+
// Dynamic with evaluate (avoid this)
6161
funcName = "getName";
62-
dump(evaluate('test.#funcName#()'));
63-
// UDF call via bracket notation
62+
dump( evaluate('test.#funcName#()') );
63+
64+
// Dynamic with bracket notation (better!)
6465
funcName = "getName";
6566
dump( test[funcName]() );
6667
```
6768

68-
These three different types of function calls are:
69-
70-
- Calling the user-defined function `getName()` from the component.
71-
- Dynamic function name with evaluate function.
72-
- User-defined function via bracket notation.
73-
74-
All three different function calls return the same content "Susi" as defined in the CFC page.
75-
76-
## Example 3: Passing Arguments via URL/Form Scopes as Array
69+
All three return "Susi", but bracket notation is cleaner and safer than `evaluate()`.
7770

78-
Lucee allows passing URL and Form scope data as an array instead of a string list.
71+
## URL/Form Arrays
7972

80-
// example3.cfm
73+
When you have multiple form fields or URL parameters with the same name, Lucee normally merges them into a comma-separated string. Adding `[]` to the name tells Lucee to return an array instead - much easier to work with:
8174

8275
```lucee
8376
<cfscript>
8477
dump(label:"URL", var:url);
8578
dump(label:"Form", var:form);
86-
// current name
8779
curr = listLast(getCurrentTemplatePath(),'\/');
8880
</cfscript>
8981
9082
<cfoutput>
9183
<h1>Countries</h1>
84+
<!--- Note the [] in country[] --->
9285
<form method="post" action="#curr#?country[]=USA&country[]=UAE">
9386
<pre>
9487
Countries Europe: <input type="text" name="country[]" value="Switzerland,France,Germany" size="30">
@@ -99,25 +92,6 @@ Lucee allows passing URL and Form scope data as an array instead of a string lis
9992
</cfoutput>
10093
```
10194

102-
// index.cfm
103-
104-
```luceescript
105-
directory sort="name" action="list" directory=getDirectoryFromPath(getCurrentTemplatePath()) filter="example*.cfm" name="dir";
106-
loop query=dir {
107-
echo('<a href="#dir.name#">#dir.name#</a><br>');
108-
}
109-
```
110-
111-
In this cfm page, URL and form scopes are available. The names are used twice.
112-
113-
- The query string on the URL scope has the same name `country` twice. Similarly, the form also has two fields with the same name `country`.
114-
- Execute this cfm page in the browser & submit the form. It shows a single URL string list in merged format instead of two fields & Form fields also merged as a single `country` field.
115-
- Adding square brackets behind the name `country[]` means it returns two separate strings in array format. You will see the difference in the browser while dumping that name with square brackets.
116-
117-
These simple methods are helpful for defining variables in different ways.
118-
119-
## Footnotes
120-
121-
Here you can see the above details in the video
95+
With `country` you get `"USA,UAE"` (string). With `country[]` you get `["USA","UAE"]` (array).
12296

123-
[Lucee Hidden Gems](https://youtu.be/4MUKPiQv1kAsss)
97+
Video: [Lucee Hidden Gems](https://youtu.be/4MUKPiQv1kA)

docs/recipes/hooks-and-monitors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# Hooks and Monitors
2020

21-
Lucee provides two powerful extension mechanisms that allow you to inject custom functionality at different points in the application lifecycle: **Hooks** and **Monitors**. These systems enable you to extend Lucee's capabilities, implement custom initialization logic, collect runtime metrics, and integrate with external systems seamlessly.
21+
Two extension mechanisms for custom functionality: **Hooks** run at lifecycle points (startup), **Monitors** collect runtime metrics (requests, actions, intervals).
2222

2323
## AI-Optimized Technical Reference
2424

docs/recipes/http-logging.md

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,16 @@
1919

2020
# Logging CFHTTP Calls
2121

22-
As of Lucee 6.1.0.135, all `cfhttp` calls are logged by default to a dedicated `http` log file at the log level `info`. This logging behavior provides more visibility into HTTP requests made through Lucee applications, helping to track external requests easily.
23-
24-
## Default Logging Behavior
25-
26-
In the default setup, Lucee logs HTTP requests with the following settings:
27-
28-
- **Log File**: `http.log` (If the `http.log` log does not exist, entries are directed to `application.log`).
29-
- **Log Level**: `info`.
22+
All `cfhttp` calls are logged by default to a dedicated `http` log file at `info` level (falls back to `application.log` if `http.log` doesn't exist).
3023

3124
### Example Log Entry
3225

33-
An example entry for a `cfhttp` call might look like this:
34-
3526
```plaintext
3627
"TRACE","pool-3-thread-2","10/29/2024","18:31:04","cftrace","httpRequest [GET] to [https://lucee.org], returned [200 OK] in 294ms, at /index.cfm:10; /index.cfm.callLucee():20"
3728
```
3829

39-
This log entry includes:
40-
41-
- **Request Details**: Method (`GET`), URL (`https://lucee.org`)
42-
- **Response Status**: `[200 OK]`
43-
- **Response Time**: `294ms`
44-
- **Source Location**: Code locations responsible for the request.
45-
46-
## Changes in Logging Behavior (Pre-Lucee 6.1.0.135)
47-
48-
In earlier versions of Lucee, before version 6.1.0.135:
30+
Includes method, URL, response status, time, and source location.
4931

50-
- **Log File**: Only `application.log` was used for logging HTTP requests.
51-
- **Log Level**: `trace` instead of `info`.
32+
## Pre-6.1.0.135 Behavior
5233

53-
The change to a dedicated `http` log and `info` level helps separate HTTP logs from other system logs, improving clarity.
34+
Earlier versions logged to `application.log` at `trace` level instead.

0 commit comments

Comments
 (0)