Custom FarCry 4 Rule: Recently Updated Pages

Rules in FarCry are cool. Rules let you easily add dynamic content to a page, such as News or Events, simply by placing rules into a Container when you are viewing the site in Design Mode.

This example is very simple and makes use of FarCry 4's "Form Tools". The two cfproperty tags are all we need for FarCry to be able to deploy the appropriate table and fields to the database and to display and save the form when the user is editing the rule. Nice :) The only other required pieces of code are for the component to extend farcry.core.packages.rules.rules (or another rule that has already extended that component), and to implement a public function called execute() so that we can display something.

My ruleRecentlyUpdated.cfc rule simply does a query for dmHTML records whose status match the allowed options in request.mode.lValidStatus - i.e. if you are logged in and are in Draft Mode then Drafts will be included, otherwise it defaults to Approved page only - and sorts them in descending order using the datetimelastupdated field. It also makes use of a display method so that you can choose which display teaser you would like to use for output. See the sample code below...

ruleRecentlyUpdated.cfc (in /farcry/projectname/packages/rules)

displayTeaserRecentlyUpdated.cfm (in /farcry/projectname/webskin/dmHTML)

* Note that I have only tested this with MS SQL, though I assume it will work with most other DB servers. Use this code at your own risk ;)

For my use case this was simply all I needed, however you could make a number of improvements to the functionality of this rule, such as:

  • add a property to make the unordered list HTML tag optional
  • select or exclude pages that are children of a particular navigation node
  • select pages that belong to particular categories
  • check pages that may be part of a members area that requires a login and include/exclude them as appropriate

If you want to look at rules, form tools and other stuff in more depth check out the FarCry 4 Developers Guide.

Extending richtext.cfc in FarCry 4

I've been a really hopeless blogger lately so I thought I'd kick things back into gear with some FarCry 4 goodness. FarCry 4 now uses TinyMCE for it's rich text editor and any customisations or editor replacements are done by extending richtext.cfc. This quick example just shows you how to change the configuration options of TinyMCE.

I wanted to specifically make changes to the HTML formatting output, HTML editor window, and default table attributes, but there is a whole lot more you can do with TinyMCE too - check out the TinyMCE Wiki for a full reference of configuration, button and plugin options.

In your project you will need to create a formtools folder inside /farcry/yourproject/packages, and create a file called richtext.cfc. This new component will extend farcry.core.packages.formtools.richtext and will override the getConfig() function - pretty straight forward really :)

Below is my sample richtext.cfc (use at your own peril, comments are welcome!)

After your new file is in place and has been saved you'll need to do an ?updateapp=1 for the new configuration to take effect. That should be all there is to it!

I'm on the Goog!

Last week I noticed that my posts are now aggregated on "the 'Goog" so I thought I'd give the site a bit of a brush up this weekend :)

I've given the design a quick refresh, still sticking with the dark theme and adding a bit more of a Vista touch to it (yeah, I'm a sucker for that glass effect). I've also worked in some inline comments for BlogCFC using Dan Vega's recent post as a guide. (Thanks Dan, it helped a lot!).

Since I don't have an About Me page I should introduce myself a little. I'm a 26 year old Aussie and I've been working with ColdFusion for the last couple of years. I'm currently working on a couple of FarCry sites and other internal apps for the government department I work for. I think CF is the most elegant language I've had the pleasure of working with on the web and can't wait for ColdFusion 8 to make my job even easier (and more enjoyable!). I also created the webDU 2007 countdown gadget earlier this year, which had about 150 downloads (not too shabby considering everyone loves Macs these days, haha).

I'm also addicted to Guitar Hero II on the Xbox 360 :) I'll probably throw my gamer card up on the home page in the next few days (it's currently just a blank canvas).

In the near future I hope to cover some beginner aspects of FarCry 4.x, perhaps on Custom Types, Scaffolding, Custom Admin and Formtools. Armed with a small amount of knowledge you can build some pretty neat stuff in no time at all... Needless to say I think FarCry rocks!

Anyway, enough of my rambling. I look forward to having some new readers and hopefully I can contribute something back to the community.

Cheers.