home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 April / APC443.iso / features / grpware / coldfus / coldfusi.exe / data1.cab / Examples / docs / pubdocs / 5-under2b.cfm < prev    next >
Encoding:
Text File  |  1998-10-08  |  5.7 KB  |  112 lines

  1. <CFSET Title = "Under the Hood, Pt. 2 Continued">
  2. <CFINCLUDE TEMPLATE="_header.cfm">
  3.  
  4. <h3>Under the Hood, Pt. II Continued</h3>
  5.  
  6. <P>Now that you've seen how <CODE><CF_ShowObject></CODE> handles <I>explicit</I> calls,
  7. let's see how <CODE><CF_ShowContent></CODE> handles <I>implicit</I> calls.</P>
  8.  
  9. <H4><CF_ShowContent></H4>
  10.  
  11. <P>The first thing <CODE><CF_ShowContent></CODE> has to do is figure out what
  12. page it's on, what location it's dealing with, and what instances should be shown
  13. for that page, location, and time.</P>
  14.  
  15. <P>First, the function <CODE>GetTemplatePath()</CODE> is used to determine what 
  16. page we're dealing with. If the page is correctly registered in the database,
  17. the query GetPageID will have one (and only one) record.</P>
  18.  
  19. <BLOCKQUOTE><PRE><CFQUERY DATASOURCE="CFexamples" NAME="GetPageID">
  20. SELECT * FROM PubPages
  21. WHERE TemplatePath = '#GetFileFromPath(GetTemplatePath())#'
  22. </CFQUERY>
  23.  
  24. <CFIF GetPageID.RecordCount IS 0>
  25.     <CFSETTING ENABLECFOUTPUTONLY="NO">
  26.     <CFOUTPUT><!-- (CF_ShowContent) ERROR: PageID not found!! --></CFOUTPUT>
  27.     <CFEXIT>
  28. </CFIF></PRE></BLOCKQUOTE>
  29.  
  30. <P>Then we use CFPARAM to default the Location number to 1 (if none was specified).</P>
  31.  
  32. <BLOCKQUOTE><PRE><CFPARAM NAME="Attributes.Location" DEFAULT="1"></PRE></BLOCKQUOTE>
  33.  
  34. <P>Now we're ready to query the database and see exactly which instances should
  35. appear (and in what order). Notice that it's possible to use the URL variable 
  36. CurrentTime to see how the site would look at a different time.</P>
  37.  
  38. <BLOCKQUOTE><PRE><CFPARAM NAME="URL.CurrentTime" DEFAULT="#Now()#">
  39.  
  40. <CFQUERY DATASOURCE="CFexamples" NAME="GetInstances">
  41. SELECT PubObjects.*, PubInstances.*, PubDataClasses.*
  42. FROM PubObjects, PubInstances, PubDataClasses
  43. WHERE PubObjects.ObjectID = PubInstances.ObjectID
  44.     AND PubObjects.ClassID = PubDataClasses.ClassID
  45.     AND PageID = #GetPageID.PageID#
  46.     AND (StartTime < #CreateODBCDateTime(URL.CurrentTime)# OR StartTime = Null)
  47.     AND (EndTime > #CreateODBCDateTime(URL.CurrentTime)# OR EndTime = Null)
  48.     AND Location = #Attributes.Location#
  49. ORDER BY Priority DESC
  50. </CFQUERY></PRE></BLOCKQUOTE>
  51.  
  52. <P>At this point, the query GetInstances contains all of the instances that 
  53. should appear. Now we loop over the query and do the same thing we did for
  54. <CODE><CF_ShowObject></CODE>: query for the object's content, pour it
  55. into an associative array, then render the HTML.</P>
  56.  
  57. <BLOCKQUOTE><PRE><CFLOOP QUERY="GetInstances">
  58.  
  59.     <CFQUERY DATASOURCE="CFexamples" NAME="GetContent">
  60.     SELECT PubContent.*, PubContentTypes.*
  61.     FROM PubContent, PubContentTypes
  62.     WHERE PubContent.TypeID = PubContentTypes.TypeID
  63.         AND ObjectID = #GetInstances.ObjectID#
  64.     </CFQUERY>
  65.  
  66.     <CFSET CurrObject = StructNew()>
  67.     <CFLOOP QUERY="GetContent">
  68.         <CFSET Temp = StructInsert(CurrObject, TypeName, Data)>
  69.     </CFLOOP>
  70.     <CFSET CurrObject.ClassName = ClassName>
  71.     <CFSET CurrObject.ObjectID = ObjectID>
  72.  
  73.     <CFPARAM NAME="Attributes.ViewMode" DEFAULT="default">
  74.     <CFINCLUDE TEMPLATE="viewmode/#Attributes.ViewMode#.cfm">
  75.         
  76. </CFLOOP></PRE></BLOCKQUOTE>
  77.  
  78. <P>Note that this time, the code to render the HTML isn't stored within
  79. the custom tag itself, but instead in templates in the ViewMode subdirectory.
  80. Using the ViewMode custom tag attribute, you can choose different templates.
  81. So if you had a ViewMode/TopStory.cfm template that showed the news item in a larger
  82. font, you could use the following code:</P>
  83.  
  84. <BLOCKQUOTE><PRE><CF_ShowContent Location="1" ViewMode="TopStory">
  85. <CF_ShowContent Location="2"></PRE></BLOCKQUOTE>
  86.  
  87. <P>For the purposes of this example app, we've only included the default ViewMode;
  88. the code for it appears below, and should be pretty self-explanatory.</P>
  89.  
  90. <BLOCKQUOTE><PRE><CFOUTPUT>
  91. <P><DIV CLASS="HeadlineTeaser">#CurrObject.Headline#<BR></DIV>
  92. <DIV CLASS="TeaserTeaser">#CurrObject.Teaser#<BR></DIV>
  93.  
  94. <CFIF CurrObject.ClassName IS 'News Item'>
  95.     <DIV CLASS="LinkTeaser"><A HREF="viewfull.cfm?ObjectID=#CurrObject.ObjectID#">More Info</A></DIV>
  96. <CFELSEIF CurrObject.ClassName IS 'File with Description'>
  97.     <DIV CLASS="LinkTeaser"><A HREF="binarydata/#Replace(Replace(URLEncodedFormat(CurrObject.File),"%2E",".","ALL"),"+","%20","ALL")#">Download File</A></DIV>
  98. <CFELSEIF CurrObject.ClassName IS 'Hyperlink'>
  99.     <DIV CLASS="LinkTeaser"><A HREF="#CurrObject.HREF#">Go to page</A></DIV>
  100. </CFIF>
  101.  
  102. <!--- If browser is in Admin mode, display editing icons --->
  103. <CFIF IsDefined("Cookie.PubAdminMode")>
  104.     <A HREF="admin/properties.cfm?ObjectID=#ObjectID#"><IMG SRC="open.gif" WIDTH=16 HEIGHT=14 BORDER=0 ALT="Open" ALIGN="TOP"></A>
  105.     <A HREF="admin/deleteinstance.cfm?InstanceID=#InstanceID#"><IMG SRC="delete.gif" WIDTH=15 HEIGHT=16 BORDER=0 ALT="Delete" ALIGN="TOP"></A>
  106. </CFIF>
  107.  
  108. </CFOUTPUT></PRE></BLOCKQUOTE>
  109.  
  110. <CFSET HREF = "6-learnmore.cfm">
  111. <CFSET Link = "Learning More">
  112. <CFINCLUDE TEMPLATE="_footer.cfm">