Justin Carter's madfellas.com

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.