Wiki
Clone wikiLucee / Cookbook ApplicationContext Set Mapping
Set a regular Mapping
Lucee allows to set directory mappings in your Application.cfc, this mappings are only valid for the current request.
#!javascript // Application.cfc component { this.mappings['/shop']=getDirectoryFromPath(getCurrentTemplatePath())&"shop"; }
Now you can simply use that mapping in your code
#!html <cfinclude template="/shop/whatever.cfm"> <!--- load a template from the "shop" mapping ---> <cfset cfc=new shop.Whatever()><!--- load a CFC from the "shop" mapping (see also "this.componentpaths" for handling components) --->
Component and Custom Tag Mappings
The previous example only has shown how to do a regular mapping, but Lucee is providing 3 types of mappings, regular component and custom tag mappings.
#!javascript // Application.cfc component { this.componentpaths=[getDirectoryFromPath(getCurrentTemplatePath())&"testbox"];// mapping testbox components this.customtagpaths=[getDirectoryFromPath(getCurrentTemplatePath())&"helper"];// mapping a collection of helper custom tags }
Advanced
In the previous example we have simply set a path, like you can see in the admin a mapping can contain more data than only a physical path, of course you can use this settings also with a mapping done in the Application.cfc
#!javascript // Application.cfc component { this.mappings['/shop']={ physical:getDirectoryFromPath(getCurrentTemplatePath())&"shop", archive:getDirectoryFromPath(getCurrentTemplatePath())&"shop.lar", primary:"archive" }; }
#!html <cfinclude template="/shop/whatever.cfm">
Of course this can be done for all mapping types
#!javascript // Application.cfc component { this.componentpaths=[{archive:getDirectoryFromPath(getCurrentTemplatePath())&"testbox.lar"}];// loading testbox from a archive this.customtagpaths=[{archive:getDirectoryFromPath(getCurrentTemplatePath())&"helper.lar"}];// a collection of helper custom tags }; }
Updated