Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Objectives

...

titleWork in Progress

...

Updating the course for FarCry 6.x. If you can help let us know! Put your notes in the comments for the page.

Additional topics to be considered for this unit:

  • introduce the difference between views on the content type (ie type or listing views) and views on individual content items/instances
  • introduce friendly URLs; these will be covered in more detail in Webskin II
  • explain the use of the webskin tracer; developers need to learn this immediately
  • introduce view inheritance ie. views coming from core and plugins as well as the project
  • explain how headers and footers work
  • explain in detail the way skin:view works
  • give examples of relevant @@viewdecorators where possible
  • explain grid tags; especially with respect to mollio skeleton

Objectives

Excerpt

In this unit we learn about webskins: the "view" for FarCry Framework. Webskins form the presentation tier of any FarCry application. By the end of this unit you should have a basic understanding of how webskins are managed, their relationship to content types and how to create your own.

The COAPI

The FarCry framework is based on a variation of the classic Model-View-Controller pattern. The COAPI (or Content Object API) is a high level name for the MVC engine inside FarCry. Without getting bogged down in the details of the framework, its good to have a high level or "helicopter" view of how things work under the hood. We'll expand on these themes gradually as you go through the course.

Mockup

Requests from users are processed by FarCry's built-in "smart controller" which automatically determines wiring based on the URL convention or the friendly URL sub-system. The COAPI always ends up calling a principal content type (a special type of class) that manages how we interact with the model and view. When thinking of views (or webskins) its important to realise that they are always executed in the context of a specific content type.

It's not at all important for developers to understand how the COAPI works, but hey, for those that want the details we've added some advanced info boxes where relevant.

The Webskin

The webskin is a templating layer that effectively translates your data into a view. Typically this is a complete HTML page or fragment of HTML representing a content teaser or some other element used in assembling a page. But a webskin could just as easily be outputting a form, RSS, XML or other format.

In its basic form we can run a webskin on an object by using the following URL Syntax:

Code Block
titleURL Syntax

http://superheroes.local?objectid=E689D66F-96FD-E9F6-B1AF64B8DAE78A69&view=displayPageStandard

The url above is running the webskin "displayPageStandard" on the object with the objectid of "E689D66F-96FD-E9F6-B1AF64B8DAE78A69"

...

Excerpt

In this unit we learn about webskins: the "view" for FarCry Framework. Webskins form the presentation tier of any FarCry application. By the end of this unit you should have a basic understanding of how webskins are managed, their relationship to content types and how to create your own.

The COAPI

The FarCry framework is based on a variation of the classic Model-View-Controller pattern. The COAPI (or Content Object API) is a high level name for the MVC engine inside FarCry. Without getting bogged down in the details of the framework, its good to have a high level or "helicopter" view of how things work under the hood. We'll expand on these themes gradually as you go through the course.

Mockup
mvc-diagram
mvc-diagram
Version2
Namemvc-diagram

Requests from users are processed by FarCry's built-in "smart controller" which automatically determines wiring based on the URL convention or the friendly URL sub-system. The COAPI always ends up calling a principal content type (a special type of class) that manages how we interact with the model and view. When thinking of views (or webskins) its important to realise that they are always executed in the context of a specific content type.

It's not at all important for developers to understand how the COAPI works, but hey, for those that want the details we've added some advanced info boxes where relevant.

The Webskin

The webskin is a templating layer that effectively translates your data into a view. Typically this is a complete HTML page or fragment of HTML representing a content teaser or some other element used in assembling a page. But a webskin could just as easily be outputting a form, RSS, XML or other format.

In its basic form we can run a webskin on an object by using the following URL Syntax:

Code Block
titleURL Syntax

http://superheroes.local?objectid=E689D66F-96FD-E9F6-B1AF64B8DAE78A69&view=displayPageStandard

The url above is running the webskin "displayPageStandard" on the content item with the objectid of E689D66F-96FD-E9F6-B1AF64B8DAE78A69

Pretty ugly, eh. But not to worry. In practice the Friendly URL (FU) engine dynamically changes these links to beautiful looking URLs. For example, /hero/batman

Where to Find Webskins

Webskins are all located in a single folder under your project root called "webskin" funnily enough. Inside that directory branch you should find a single folder for each content type you want a webskin for.

Code Block
titleExample Webskin Directory Structure

c:\farcry
[install-root]
\farcry-express-install
  \webroot
   \farcry
     \projects
       \myproject
         \webskin
           \dmHTML
           \dmNews
           \dmEvent
           \myContentType
Tip
titleWebskin InheritenceInheritance

Webskins can be stored in the core framework, and any plugin as well as your current project. However, any webskin placed in your project with the same name as an existing webskin will always be overridden by your project's webskin.

...

  1. Login to the Webtop and click on the Home Page dmHTML object in the site tree (the white page icon... not the blue dmNavigation object)
  2. Copy the objectid of this object to the ClipBoard (located at the bottom of the summary for the object or in version 6-0-16, under the Miscellaneous tab in the ObjectID section)  
  3. Now, locate the ./webskin/dmHTML folder in your project
  4. Take note of the current webskins in that folder.
  5. Now enter a url to call each of the various webskins in that folder using the following format http
    Code Block
    titleExample URLs Only
    
    http://superheroes.locallocalhost:8888/index.cfm?objectid=E689D66F-96FD-E9F6-B1AF64B8DAE78A69&view=displayPageStandard
    
    http://superheroes.locallocalhost:8888/index.cfm?objectid=E689D66F-96FD-E9F6-B1AF64B8DAE78A69&view=displayPage3Col
    
    http://superheroes.locallocalhost:8888/index.cfm?objectid=E689D66F-96FD-E9F6-B1AF64B8DAE78A69&view=displayTeaserStandard
    
  6. Discuss how this forms the basis of almost ALL web applications

Creating Webskins

The "smart controller" wires up the content type, the content item and webskin (view) by convention based on the parameters in the URL.

Webskins are literally just ColdFusion templates. Any file with a .cfm extension in a directory under ./myproject/webskin will be automatically registered as a webskin by the FarCry Framework. Consequently only files that you intend to be webskins should ever be stored here. To create a webskin simply create the template in the correct directory and RELOAD/RESTART the application.

Note
titleReloading/Restarting The Application To Recognise Webskin Changes

When a FarCry application starts it works out all the available webskins for every content type and stores them in memory. Every time you add create a new webskin file you need to reload the application in order for the system to recognise it. If you are logged in you can reload the application from the "Tray Menu" or by simply running a page with &updateapp=1 at the end of the URL (if you are logged in). . (Note: Your updateapp key may be set to a value other than 1. Check inside your farcryConstructor.cfm in your webroot to confirm).

Alternatively, if you only want to reload part of the application, go into the [ webtop / admin / developer utilities / reload application ] and simply select the options you wish to reload. This is a handy tab to have open at all times while your developing and constantly adding/updating webskins and metadata.

...

Tip

Changing webskins does NOT require an application restart. You only need to restart if you are adding, removing or renaming webskin files.

Naming Webskin Templates

Although you can give your webskin template any file name, in practise it makes sense to follow the naming standards used by the rest of the community. The following table outlines common naming prefixes for templates and explains their uses within the FarCry framework. An asterisk (*) denotes a wildcard, where you would use your own unique name to differentiate templates of similar purpose.

Template Name

Purpose

Examples

display*

General prefix for all display templates. By default FarCry allows anonymous users to view anything prefixed with display*

displayPage*

A full page template display, typically incorporating header and footer HTML, and designating the entire page layout. These templates are available by default in the content editing wizards for contributors in community plugins, such as FarCry CMS.

./dmHTML/displayPageHome.cfm

displayPageStandard.cfm

In the absence of any additional criteria, FarCry will attempt to display a content object item with this template, assuming it is available. It is in effect the "standard" full page template view.

displayTeaser*

A teaser view such as a title and short copy with a link to the full page view. Often used for listing other content objects on a page. Automatically recognised by many publishing rules.

./dmHTML/displayTeaserFeature.cfm

displayTeaserStandard.cfm

Similar to displayPageStandard, in that if no other criteria is given the framework will attempt to render a given content object with this template, assuming it is available and a teaser view is required.

displaySearchResult.cfm

Used in the farcryverity plugin search plugins to provide a universal search result teaser. As individual content types might be better suited to different teasers you can provide your own as needed.

edit*

General prefix for editing a content type. By default, these views are secured to content publishers only and are not accessible by anonymous users.

./dmProfile/editOwnProfile.cfm

edit.cfm

Default edit handler. Typically this is not present, at least in simple content types, as the framework will automatically build edit handlers from the formtool metadata. However, like most things in FarCry you can override this as needed.

These are just a few of the regularly used webskin names within the FarCry framework.

Hooking Up The Webskin To Data

Every time a webskin For a complete list of reserved webskin template names review: https://farcry.jira.com/wiki/display/FCDEV50/Webskin+Templates

Hooking Up The Webskin To Data

Every time a webskin is invoked it is done so in the context of a specific content objecttype.

For example, viewing a particular news article in with a displayPageStandard, or a product item with displayPageProduct.cfm, or whatever. FarCry always provides the entire content object item record to the webskin (or view) as a structure called stobj.

stobj contains the typename, and all the property keys and values for the object in question, including array properties.

Tip
titleArray Properties

Array properties are automatically generated provided as an actually a CF array in the structure value field. The array contains all the related object references as UUID values. More on this later.

The data contained in the stobj structure can be referenced in the normal wayas a simple ColdFusion variable, and then combined with mark-up to produce the desired output. The similarity between this and any normal procedural ColdFusion template is deliberate - the framework authors have tried hard to make the creation of webskins or views very similar to building a simple ColdFusion template.

Code Block
titleSimple Example of a News Template
<<cfsetting enablecfoutputonly="true">
<!--- // Dead Simple Example Webskin Template -- Dead Simple --->
<cfoutput>
  <h1>#stobj.title#</h1>
  #stobj.body#
</cfoutput>
<cfsetting enablecfoutputonly="false">
Tip
titleWhitespace Management

FarCry best practice sets <cfsetting enablecfoutputonly="true" /> at the top of your webskin and <cfsetting enablecfoutputonly="false" /> at the bottom. This means simply that any content you want displayed must appear between <cfoutput></cfoutput> tags. Try to avoid putting custom tags within <cfoutput> - without special treatment (eg. using cfsilent internally) the custom tag will output all its contents as whitespace.

Webskin

...

Decorators

Every template can be supplemented with additional metadata, called a "decorator". You should make a habit of this adding relevant decorators as it makes the whole system read much better, helping to provide human readable template names, inline documentation and so on. Metadata is incorporated by including a series of specific comments at the top of each template.

Name and contact email for the responsible developer.

Attribute

Description

@@displayname:

Human readable display name for the template. Otherwise the framework will display the filename instead.

@@description:

Longer description about the template's purpose. This can run to any length but is typically a paragraph only.

@@author:

For a complete list of decorators and their uses, see:https://farcry.jira.com/wiki/display/FCDEV60/Summary+of+View+Decorators

Template metadata is always stored in a ColdFusion comment.

On initialisation, FarCry scans the registered webskins for their additional metadata and stores it in memory. If you make a change to the metadata you may need to re-start the application in order to see the change come into effect.

Code Block
titleSample Metadata Attached With Decorators
<!--- @@displayname: Core Home Page --->
<!--- @@description: Home page for the FarCry Core developer portal. --->
<!--- @@author@@Cachestatus: Matthew Bryant (mbryant@daemon.com.au)1 --->
<!---> 

...

@@Cachetimeout: 60 --->
<!--- @@Fualias: home --->

Walkthrough: Create displayPageSuper.cfm

...

  1. Locate the ./webskin/dmHTML folder in your project
  2. Create a file called displayPageSuper.cfm
  3. Write up some basic HTML in a <cfoutput>
    Code Block
    title./webroot/farcry/projects/myproject/webskin/dmHTML/displayPageSuper.cfm
    <!--- @@displayname: Demo Template --->
    <cfoutput>
    <h1>Hello Cruel World</h1>
    </cfoutput>
    
  4. Reload the application to pick up the template change. Use the [Reload Application] tool in the webtop.
  5. Select the Site Overview Tab. Edit the FarCry Support HTML page and change its template to the one you just created.
  6. Save and Preview the page. Check the HTML source and discuss with your instructor.
  7. Edit your template and add a cfdump to the page for stobj
    Code Block
    <cfdump var="#stobj#" label="Content Object" />
    
  8. Save and preview the page.

...

FarCry has a special custom tag library dedicated to making life easier when building webskins. In includes all sorts of goodies from building navigation, to breadcrumbs, to rendering other views and more. You can find this library in the core framework at: ./core/tags/webskin To make use of these tags you will need to import them first.

...

For a complete list of webskin tags see:http://docs.farcrycore.org/p600/

Code Block
titleImporting Custom Tag Libraries
<!--- @@displayname: Home Page --->
<!--- @@author: Matthew Bryant (mbryant@daemon.com.au)--->

<!--- import tag libraries --->
<cfimport taglib="/farcry/core/tags/webskin" prefix="skin" />

<skin:breadcrumb />
Tip
titleProject Tag Libraries
We recommend creating your own custom tag libraries under the project folder and importing them in the same way: ./myproject/tags/mytaglibrary
/core/tags/webskin" prefix="skin" />

<!--- breadcrumb; detects position in the site tree and builds a breadcrumb --->
<skin:breadcrumb />
Tip
titleProject Tag Libraries

We recommend creating your own custom tag libraries under the project folder and importing them in the same way: ./myproject/tags/mytaglibrary

Composite Views

In practice, web pages in FarCry are assembled from multiple webskins. While you can do a lot with custom tags, the best way to build web pages is by compositing multiple webskins together.

Consider the following real world examples of composite views from the Fandango theme.

Mockup
webskin-composite
webskin-composite
Version1
Namewebskin-composite
Note

FarCry doesn't prescribe a specific templating architecture - you can get pretty sophisticated in your approach or keep it dead simple. Fandango is a good best practice starting point.

Building a Composite View

A typical starting point for any composite view is working with headers and footers. Its very common to have a similar header across all web pages, albeit with slight variations such as page title, highlighted navigation and so on. Likewise the footer structure.

You can call another view directly using the skin:view tag. skin:view is a real workhorse - we use it all the time.

Code Block
titleExample from ./dmHTML/displayPageHome.cfm

<div id="main">
	<div class="container_12">
		<div class="grid_12 content">
		<skin:view typename="#stobj.typename#" objectid="#stobj.objectid#" webskin="#url.bodyView#" />
		</div>
	</div>
</div>

View Inheritance

FarCry is an object oriented framework. All content types extend the core types component (an abstract class). Any views associated with types are automatically inherited by other content types, such as our dmHTML content type.

More on content types later. Long story short, you can assume that any view located in ./webskins/types is available to all content types.

Looking at our dmHTML content type in Fandango, we have at least the following views available:

  • displayPageStandard
  • displayTeaserStandard
  • displayHeaderStandard
  • displayFooterStandard
  • displayBody
  • displaySimpleSearchResult

Webskin Tracer

The tray that appears at the bottom of the website when you are logged in, contains a marvellous developer utility called the "Webskin Tracer". You can activate it for any page by simply selecting the webskin tracer option.

Image Added

The entire pages composite of views is laid bare; highlighting each webskin executed for the page. Select a specific view and the HTML fragment is highlighted, with a tooltip detailing exactly where the webskin template can be found.

Image Added

FarCry Profiler

The FarCry profiler details how long each part of your request is taking to execute on the server. This is a great tool for identifying slow running pages and candidates for caching.

Image Added

Tip

You can turn on the webskin tracer and profile tools without being logged in by using your projects "secret key" on the URL:http://localhost:8888/index.cfm?objectid=E689D721-B6C9-605B-DE1D813E4CDA3339&tracewebskins=farcry

Walkthrough: Creating a Composite View

  1. turn on the webskin tracer
  2. review various pages with your instructor
  3. Add Header & Footer views to ./dmHTML/displayPageSuper.cfm

Walkthrough: Putting It All Together

...