HTML Helper

Introduction

The HTML Helper is a core ColdBox CFC that abstracts the creation of any HTML entity. It provides consistent and secure rendering of HTML within ColdBox applications.
1
coldbox.system.modules.HTMLHelper.modles.HTMLHelper.cfc
Copied!
Please check out the latest CFC Docs for all the methods available to the HTML Helper.
There is no special setup needed to use it in a ColdBox application, it's already baked in. Just reference the object by the html prefix and call the desired function within any layout or view.
1
// CFML
2
#html.button(name = "searchView", value = "View")#
3
4
// HTML Output
5
<button name="searchView" id="searchView" type="button">View<button>
Copied!
By specifying the name of the element and not the id, both attributes are output using the same value. You can specify a different value for the id attribute by explicitly defining it.
1
// CFML w/ differnet name and id
2
#html.button(name = "searchView", id="id_searchView", value = "View")#
3
4
// HTML Output
5
<button name="searchView" id="id_searchView" type="button">View<button>
Copied!
You can also pass in any attribute to the registered functions and if it does not match an argument it is passed through into the HTML element:
1
// CFML w/ differnet name and id
2
#html.button(
3
name = "searchView",
4
id="id_searchView",
5
value = "View",
6
class = "btn btn-default"
7
)#
8
9
// HTML Output
10
<button
11
name="searchView"
12
id="id_searchView"
13
type="button"
14
class="btn btn-default">
15
View
16
<button>
Copied!

Injecting the HTML Helper

You can inject the HTML helper anywhere you like by using the following registered mapping: [email protected]
1
property name="html" inject="[email protected]";
Copied!
Last modified 7mo ago
Copy link
Edit on GitHub