Last week, I was introduced to shortcuts, which are a part of APEX that I'd never noticed before, but which has apparently been around for a long time. I'm really impressed by the power they provide (and they happened to be the perfect solution for the problem I was working on, which was a nice bonus).
Shortcuts are defined under Shared Components (in the User Interface block), and can be referenced in a bunch of different places. Here's the sidebar description of what a shortcut is:
Use Shortcuts to write frequently used code once and then reference it in many places within your application. Shortcuts also allow for dynamic generation of code in places that typically only support static text.
And here's the list of places they can be used:
- Region Source for regions of type HTML_WITH_SHORTCUTS
- Region Templates, Region Headers & Footers
- Item Labels
- Item Default Value
- Item Post Element Text
- Item Help Text
- HTML Header of a page
For my particular problem, I needed a region on several pages whose content was dynamically generated based on the page number it was on. I considered doing this through a Page 0 region, but that hides content (making it harder to look at a page in the builder and see where the content is coming from) and gets tested for every page–a minor hit, sure, but something to avoid. On the other extreme, I could have just created a PL/SQL region and then copied it to all of the relevant pages, but then any changes would have to be made on every single page, creating large opportunities for mistakes.
Shortcuts solved all of these issues. I defined one shortcut, so future changes are easy, and then created an HTML with Shortcuts region which called the shortcut and copied it to all of the relevant pages. I can look at the page in the builder and see where my content is coming from. Win!
But look at that list of where shortcuts can be used again–there are a lot of possibilities there for adding dynamic content. And since your shortcuts can be PL/SQL, that opens up a world of possibilities.