ColdBox and Viewlets
The ColdBox Framework is fast becoming enjoyable to work with, which came as a surprise for me. Having now completed 4 projects in CB I have decided to start writing up on some of my experiences so far.
The first write-up starts at the beginning! By that I mean things I found useful when first starting a CB project. Its not a deep read into CB just some random stuff that helped me out when first starting with the Framework.
Viewlets
I always found myself creating a folder called 'viewlets', why? Well sometimes things I wanted to reuse again and again seemed to fit nicely here. I think it was on the CB forums someone told me to do this and it stuck.
Having taken this approach to display simple html snippets I found I had built quite a large collect of viewlets I could use time and time again across all my projects. CB does not have this folder as standard but I think it should. Of course reusability depends completely on how you build them!
Calling viewlets was simple: as the documentations shows...
2#renderView('viewlets/forms/search')#
Meta and Title Tags
Every page needs them but I sometimes forgot! I always set a default for the variables in my layout. I found the way ColdBox does this very useful, not just for meta variables buy any variables! No more... 'variable is undefined' message.
2<title>#Event.getValue("title", "My Default Var")#</title>
3<InvalidTag name="description" content="#Event.getValue('description', ')#" />
4<InvalidTag name="keywords" content="#Event.getValue('keywords', ')#" />
5<base href="#getSetting('htmlBaseURL')#">
This is just one way to set defaults in CB. In handlers I often used a init() method or a preHandler method to set page defaults such as my default login status for a particular handler. I could of course also use an interceptor. There is just so many ways within the framework to do the same thing. There is no one way I can say is better than the other as it comes down to your project and what you're trying to achieve.
Anyhow time for bed now, it's only been 3 months working in CB but I have so much more to write-up on the things I have found. More to follow.




