Glossary CFC

The inspiration for this cfc came to me whilst reading an article by Michael Dinowitz in the excellent Fusion Authority Quarterly Update called Making Google Pay (Part 1). Michael explained why having a glossary on a Website can be a good thing for your users and search engines. I thought it would be a good idea to write something in Coldfusion that allowed glossary functionality to be employed in web applications. E.G. a CMS.

What is glossary cfc?
Glossary CFC is a Coldfusion component that searches through a string of text looking for words that you have designated as being part of your Website's glossary. As it finds a glossary word it wraps it in a hyperlink pointing to the words definition on the glossary page, before finally returning the full text with all the glossary words found in it hyper-linking to their definition. You can see an example of Glossary CFC running here

Why have a glossary page on your site?

  1. Help new users by making your site more user friendly. E.G. All industry specific words on your site can link to their own definitions. This can help new user's understand concepts on your Website that they might not be familiar with.
  2. Google likes internal links on a Website. Having a glossary can be a powerful way to improve Google pagerank.

How does it work?
It takes 3 required attributes.

  1. glossaryOfWords - The list of words you want in your glossary.
  2. textToRead - The string of text you want to check for glossary words in.
  3. templateName - The name of the .cfm template displaying the actual defintions of the glossary words. That each glossary word found will link to.
It outputs your text string with each glossary word hyperlinked to its definition.

Suggested Usage
Although its possible to use a static list of words for the value of the glossaryOfWords attribute this value is best stored in a database. In each record there should be aa seperate field. That way the Websites glossary page and value for glossaryOfWords can updated by CMS users as they wish.

Ideally the component should be integrated completely into your CMS so that as each article is input it can be glossarized with the resulting output text stored as the defintive article text.

Running Example
Click here to see Glossary cfc running as used in the code below.

<!---START init documentText with text you want to glossarize --->
<cfset documentText = "The KDE desktop offers audiokonverter, while GNOME provides audio-convert and audio-convert-mod.
       The latter two are separate projects despite their similar names.
       audiokonverter provides packages for Debian, Ubuntu, openSUSE,
       and generic RPM distributions on its home page, even though the distribution repositories
                 for Gutsy, Fedora, and the openSUSE Build Service do not offer packages for audiokonverter.
                    Packages for audio-convert are offered for Gutsy as nautilus-script-audio-convert.
                       The Fedora repositories contain audio-convert-mod, but it is not packaged for other distributions.
                          For this article I used the
      generic RPM for audiokonverter, installed audio-convert from source, and used audio-convert-mod from the Fedora repository."
>

<!---END init documentText with text you want to glossarize --->
<!---Set the words that appear in your glossary --->
<cfset glossaryList = "KDE, GNOME, Fedora, Debian, Ubuntu, openSUSE, RPM, Gutsy, repository, jkj, jkju">
<cfset glossaryList2 = "KDE, GNOME, Fedora, Debian, Ubuntu, openSUSE, RPM, Gutsy, repository">

<!---create 2 glossary instances and pass each a different glossary list--->
<cfset linuxGloss = createObject("component","glossary").init(documentText,glossaryList,"glossary.cfm")>
<cfset linuxGloss2 = createObject("component","glossary").init(documentText,glossaryList2,"glossary.cfm")>


<!---output glossarized text from cfglossary --->
<h1>Text after Glossary cfc. </h1>
<!---confirm linuxGloss glossary object was created --->
<cfif #linuxGloss.glossaryCreated()#>
<cfoutput>
<!---show the number of words in the glossary list that were searched for in the documentText value --->   
Number of words looked for: #linuxGloss.numberOfWordsLookedFor()#
<br>
<!---show the number of words from the glossaryList that were actually found in the document text --->   
Number of words found: #linuxGloss.numberOfWordsFound()#<br>
<!---Finally ouput document text with all words that were in the glossary list
hyperlinked to their definiton on glossary.cfm--->

Glossarized Text: #linuxGloss.glossarizedText()#
</cfoutput>
<cfelse><!---ELSE END --->
No Glossary words were found
</cfif>
</p>

<br>

<h1>Text after Glossary 2 cfc. </h1>

<!---confirm linuxGloss2 glossary object was created ELSE START--->
<cfif #linuxGloss2.glossaryCreated()#>
<cfoutput>
   <!---show the number of words in the glossary list that were searched for in the documentText value --->
Number of words looked for: #linuxGloss2.numberOfWordsLookedFor()#
<br>
<!---show the number of words from the glossaryList that were actually found in the document text --->   
Number of words found: #linuxGloss2.numberOfWordsFound()#<br>
<!---Finally ouput document text with all words that were in the glossary list
hyperlinked to their definiton on glossary.cfm--->
Glossarized Text: #linuxGloss2.glossarizedText()#
</cfoutput>
<cfelse><!---ELSE END --->
No Glossary words were found
</cfif>
</p>

<br>

Download You can download a zip of cfGlossary here along with docs and example code.

Subversion The latest version can be retrievied from its SVN repository here https://svn2.hosted-projects.com/stewy/myApps/glossary/

Scotch on the Rocks 2008 - Coldfusion Conference Edinburgh

Europes best and most established Coldfusion conference takes place in Edinburgh from June 04 - 06. I have been at the last 2 and they have been great. The content is of course mainly Coldfusion related but there is also an awful lot on Flex, and AIR.

With 3 seperate tracks running each day i highly recommend you get along.

See more info here

cf_MagicPager: Coldfusion custom tag

cf_Magicpager is a Coldfusion custom tag that enables pagination. Pagination allows a website's users to navigate through a large record set in a user friendly way by generating page numbered links to each page in the archive. See example here

Download the tag and docs here

The very latest version can be obtained from it's svn repository.
https://svn2.hosted-projects.com/stewy/myApps/cf_magic_pager/

  • Previous and next links are also displayed to allow user to go back and forward one page at a time.
  • The pageNumber currently being viewed is highlighted a different color from the other pageNumbers.

The tag does not retrive and display records from a database .This is left up the developer to do in a seperate process. Giving flexibility as to what and how you display your records. In this respect the tag is very much an UI tag.An example of how records could be retrived and displayed is included in the code example in the docs.

The tag is designed to be linked to the displayed records using a variable called url.pageNumber. Each time a generated page number/link is clicked a variable called url.pageNumber is set with the page number.(Its defaults to one) Use this variable to help determine what records from your recordset (archive) should queryed and displayed on each page. E.G. If the number of the page currently being processed is 7 then you should seperately retrive and display records 70 to 79 from your recordset/archive.

Possible Tag Usage:
Place tag above or/and below where the records are output on template.

<!---CFC which generates your record set/ archive --->
<cfinvoke component="archive" method="getArchive" returnvariable="result">

<!---Calling magicPager to appear above record set --->

<cf_magicPager NumberOfPages="#result.numberOfPages#" NumberOfLinksOnPage="#result.NumberOfLinksOnPage#">
</cf_magicPager>


<!---Output your records here --->
<cfoutput query="result.records">
<p>
#title#<br>
#intro#<br>
<a href="fullArticle.cfm?articleId=#articleId#">Read more...</a><br>
</p>
</cfoutput>

<!---Calling magicPager to appear below record set --->
<cf_magicPager NumberOfPages="#result.numberOfPages#" NumberOfLinksOnPage="#result.NumberOfLinksOnPage#">
</cf_magicPager>

Attributes: (all are required) These values are best calculated alongside whatever code you use to retrive your database records. A cfc would be best, returning a structure that contains your database records and these values.

  • NumberOfPages: The number of pages you want your archive to have.This can be determined by dividing the record count value of a retrived record set by the number of records/articles you want to appear on any one page. e.g. 300 records retrived / 10 records on a page: this will give a figure of 30 pages. This is the amount of pages that will be needed to display the whole archive/record set.With each individual page being generated when a user clicks on its page number.
  • NumberOfPageLinks: The amount of page links to display on screen at any one time. This figure is doubled by the tag. e.g. If you enter 10 it will generate 20 links. 10 links before current page number, (if current page number is greater than 10) and 10 links after current page number (until there are less than 10 pages left to display in archive)

BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner