Accessing ColdBox Settings in Handlers Using Wirebox

I saw a post on Twitter today:

If you are using Wirebox, this is very easy.

First, create your settings in Coldbox.cfc:

// custom settings
settings = {
  "site_name" = 'My Sample Application'
};

Then, in your handler, inject the property using the cfproperty tag:

<cfcomponent output="false" inject>

 <cfproperty name='testing_setting' inject='coldbox:setting:site_name' />

  <!--- Default Action --->
 <cffunction name="index" returntype="void" output="false" hint="My main event">
   <cfargument name="event">
   <cfargument name="rc">
    <cfargument name="prc">

   <cfset rc.welcomeMessage = testing_setting>
   <cfset event.setView("home")>
 </cffunction>

</cfcomponent>

You can see on line 3 (of this snippet), you’ll see where we are referencing ‘site_name’ and setting its value into ‘testing_setting’. Then on line 11, we are setting it into the ‘rc.welcomeMessage’ so the view can access this variable elsewhere.

I’ve posted the full working example on Github: https://github.com/ibjhb/Wirebox-Settings-Injection-Example

Let me know if you have any questions using the comments below.