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...

view plain print about
1<!---render viewlet example--->
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.

view plain print about
1<!---example in layout--->
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.

TweetBacks
Comments
Aaron Greenlee's Gravatar Thanks for the Viewlets tip! I can see how that will come in handy.
# Posted By Aaron Greenlee | 31/05/09 23:55
Glyn Jackson's Gravatar Thanks Aaron, I must say that's some impressive design on your blog, I really like the layout. :0
# Posted By Glyn Jackson | 01/06/09 09:28
Nick's Gravatar Thanks for a good advice. It is strange but it has never occurred to me to do it but the advantages are obvious.
# Posted By Nick | 07/04/10 17:48
 

About Me

Glyn Jackson, 28 years old, MD and senior developer of a development firm based in Staffordshire called Newebia Ltd. Academic background in BSc Information System & Internet Commerce. Online marketing expert (EE Ranked) and .NET developer. Has been developing with ColdFusion for 5 years and loves it. "I am not a veteran in ColdFusion but I do work on challenging projects which help me learn more about ColdFusion and if I can contribute to the community in anyway then, it's all good!"

Recommends

  • ColdFusion