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.

Comments
Nice work Justin. I'm enjoying your blog.
# Posted By Matthew Bryant | 10/6/07 5:40 PM
Thanks Mat, I'll try to keep the posts rolling :)
# Posted By Justin Carter | 10/6/07 7:59 PM
Great work! Would make a good addition to the Code by Example section of the Developer Wiki -- please consider sharing ;)
# Posted By Geoff Bowers | 10/6/07 8:40 PM
Justin, nice tip, thanks.

On a unrelated note, I see that you are using the dp.SyntaxHighlighter for highlighting your code. I recently put together a ColdFusion specific brush for dp.SyntaxHighlighter. You can find it at http://blog.tech-cats.com/2007/10/syntax-highlight...
# Posted By Boyan | 10/8/07 9:04 AM
Geoff, sure thing I'll post it on the wiki when I get a chance!

Boyan, nice one on the CF specific brush :) I was wondering if anyone had made one but hadn't come across any as yet. Thanks for the linkage, I'll try it this weekend.
# Posted By Justin Carter | 10/10/07 3:53 AM
I would like to know if you can make a custom rules that include a file... if anyone know please let me know...
# Posted By Justin | 3/18/08 4:05 PM
@Justin: There is a FarCry rule called ruleFile in the Developers' Exchange that was written by David Whiterod: http://docs.farcrycms.org/display/FCDEV30/ruleFile...

Hope that helps.
# Posted By Justin Carter | 3/19/08 12:40 AM



If you subscribe, any new posts to this thread will be sent to your email address.

BlogCFC was created by Raymond Camden. This blog is running version 5.6.001.