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

  1. <CFSETTING ENABLECFOUTPUTONLY="YES">
  2.  
  3. <!---
  4.  
  5.     This template should be called as a custom tag.  It finds
  6.     the PageID, and takes Location as a parameter, and finds
  7.     the objects    that are scheduled to appear at execution time.
  8.     
  9.     Each location on a page where dynamic content is to appear
  10.     should have a call to CF_ShowContent.
  11.     
  12. --->
  13.  
  14. <!--- First we figure out what the page ID for
  15.     the calling template is --->
  16. <CFQUERY DATASOURCE="CFexamples" NAME="GetPageID">
  17. SELECT * FROM PubPages
  18. WHERE TemplatePath = '#GetFileFromPath(GetTemplatePath())#'
  19. </CFQUERY>
  20.  
  21. <CFIF GetPageID.RecordCount IS 0>
  22.     <CFSETTING ENABLECFOUTPUTONLY="NO">
  23.     <CFOUTPUT><!-- (CF_ShowContent) ERROR: PageID not found!! --></CFOUTPUT>
  24.     <CFEXIT>
  25. </CFIF>
  26.  
  27. <!--- If location is not specified, default to 1 --->
  28. <CFPARAM NAME="Attributes.Location" DEFAULT="1">
  29.  
  30. <!--- Then we figure out which objects should appear
  31.     on this page, at this location, at this time --->
  32. <CFPARAM NAME="URL.CurrentTime" DEFAULT="#Now()#">
  33. <CFQUERY DATASOURCE="CFexamples" NAME="GetInstances">
  34. SELECT PubObjects.*, PubInstances.*, PubDataClasses.*
  35. FROM PubObjects, PubInstances, PubDataClasses
  36. WHERE PubObjects.ObjectID = PubInstances.ObjectID
  37.     AND PubObjects.ClassID = PubDataClasses.ClassID
  38.     AND PageID = #GetPageID.PageID#
  39.     AND (StartTime < #CreateODBCDateTime(URL.CurrentTime)# OR StartTime = Null)
  40.     AND (EndTime > #CreateODBCDateTime(URL.CurrentTime)# OR EndTime = Null)
  41.     AND Location = #Attributes.Location#
  42. ORDER BY Priority DESC
  43. </CFQUERY>
  44.  
  45. <!--- Now loop over each instance (an instance is
  46.         one call to one object) --->
  47.  
  48. <CFLOOP QUERY="GetInstances">
  49.  
  50.     <!--- Pour this object's data into an associative array.
  51.  
  52.         For example, Object 132 might have the following content:
  53.         
  54.         ObjectID   Type    Data
  55.         ---------  ------  -----------
  56.         132           Title   "This Story's Title"
  57.         132           Teaser  "Read this interesting article"
  58.         132        Body    "The main story would go here."
  59.  
  60.         This is in query form.  The corresponding associative
  61.         array would look like this:
  62.         
  63.         Key     Value
  64.         ------  -----------
  65.         Title   "This Story's Title"
  66.         Teaser  "Read this interesting article"
  67.         Body    "The main story would go here."
  68.         
  69.         This enables us to access the different content
  70.         by referring to StructName.Title, StructName.Teaser,
  71.         etc. rather than doing a new query each time we 
  72.         want to access a Title, Teaser, etc. --->
  73.  
  74.     <!--- This query retrieves all content information
  75.         for the current object --->
  76.     <CFQUERY DATASOURCE="CFexamples" NAME="GetContent">
  77.     SELECT PubContent.*, PubContentTypes.*
  78.     FROM PubContent, PubContentTypes
  79.     WHERE PubContent.TypeID = PubContentTypes.TypeID
  80.         AND ObjectID = #GetInstances.ObjectID#
  81.     </CFQUERY>
  82.  
  83.     <!--- This is the struct that will hold our object --->
  84.     <CFSET CurrObject = StructNew()>
  85.  
  86.     <!--- Loop over the GetContent query; for each row, insert
  87.         a row into the CurrObject struct, with TypeName as the key
  88.         and Data as the value --->
  89.     <CFLOOP QUERY="GetContent">
  90.         <CFSET Temp = StructInsert(CurrObject, TypeName, Data)>
  91.     </CFLOOP>
  92.  
  93.     <!--- Two pieces of information should also be in the CurrObject 
  94.         struct: ClassName and ObjectID. Since there was no convenient
  95.         way to work that into the CFLOOP we just did, we add them
  96.         manually. --->
  97.     <CFSET CurrObject.ClassName = ClassName>
  98.     <CFSET CurrObject.ObjectID = ObjectID>
  99.  
  100.     <!--- The CurrObject struct now contains all the content for the
  101.         current object, so it is easily accessible. Now the only
  102.         thing left to do is render the content to HTML.
  103.         
  104.         Since different situations might call for objects to be
  105.         rendered differently, the CFML that will actually render
  106.         the content is not hardcoded into ShowContent.cfm but
  107.         rather stored in "handler" files in the viewmode/ subdirectory.
  108.         
  109.         This example app only includes viewmode/default.cfm but you
  110.         can easily create your own by examining that file. --->
  111.  
  112.     <CFPARAM NAME="Attributes.ViewMode" DEFAULT="default">
  113.     <CFINCLUDE TEMPLATE="viewmode/#Attributes.ViewMode#.cfm">
  114.     
  115. </CFLOOP>
  116.  
  117. <CFSETTING ENABLECFOUTPUTONLY="NO">
  118.