home *** CD-ROM | disk | FTP | other *** search
- <CFSET Title = "Under the Hood, Pt. 2 Continued">
- <CFINCLUDE TEMPLATE="_header.cfm">
-
- <h3>Under the Hood, Pt. II Continued</h3>
-
- <P>Now that you've seen how <CODE><CF_ShowObject></CODE> handles <I>explicit</I> calls,
- let's see how <CODE><CF_ShowContent></CODE> handles <I>implicit</I> calls.</P>
-
- <H4><CF_ShowContent></H4>
-
- <P>The first thing <CODE><CF_ShowContent></CODE> has to do is figure out what
- page it's on, what location it's dealing with, and what instances should be shown
- for that page, location, and time.</P>
-
- <P>First, the function <CODE>GetTemplatePath()</CODE> is used to determine what
- page we're dealing with. If the page is correctly registered in the database,
- the query GetPageID will have one (and only one) record.</P>
-
- <BLOCKQUOTE><PRE><CFQUERY DATASOURCE="CFexamples" NAME="GetPageID">
- SELECT * FROM PubPages
- WHERE TemplatePath = '#GetFileFromPath(GetTemplatePath())#'
- </CFQUERY>
-
- <CFIF GetPageID.RecordCount IS 0>
- <CFSETTING ENABLECFOUTPUTONLY="NO">
- <CFOUTPUT><!-- (CF_ShowContent) ERROR: PageID not found!! --></CFOUTPUT>
- <CFEXIT>
- </CFIF></PRE></BLOCKQUOTE>
-
- <P>Then we use CFPARAM to default the Location number to 1 (if none was specified).</P>
-
- <BLOCKQUOTE><PRE><CFPARAM NAME="Attributes.Location" DEFAULT="1"></PRE></BLOCKQUOTE>
-
- <P>Now we're ready to query the database and see exactly which instances should
- appear (and in what order). Notice that it's possible to use the URL variable
- CurrentTime to see how the site would look at a different time.</P>
-
- <BLOCKQUOTE><PRE><CFPARAM NAME="URL.CurrentTime" DEFAULT="#Now()#">
-
- <CFQUERY DATASOURCE="CFexamples" NAME="GetInstances">
- SELECT PubObjects.*, PubInstances.*, PubDataClasses.*
- FROM PubObjects, PubInstances, PubDataClasses
- WHERE PubObjects.ObjectID = PubInstances.ObjectID
- AND PubObjects.ClassID = PubDataClasses.ClassID
- AND PageID = #GetPageID.PageID#
- AND (StartTime < #CreateODBCDateTime(URL.CurrentTime)# OR StartTime = Null)
- AND (EndTime > #CreateODBCDateTime(URL.CurrentTime)# OR EndTime = Null)
- AND Location = #Attributes.Location#
- ORDER BY Priority DESC
- </CFQUERY></PRE></BLOCKQUOTE>
-
- <P>At this point, the query GetInstances contains all of the instances that
- should appear. Now we loop over the query and do the same thing we did for
- <CODE><CF_ShowObject></CODE>: query for the object's content, pour it
- into an associative array, then render the HTML.</P>
-
- <BLOCKQUOTE><PRE><CFLOOP QUERY="GetInstances">
-
- <CFQUERY DATASOURCE="CFexamples" NAME="GetContent">
- SELECT PubContent.*, PubContentTypes.*
- FROM PubContent, PubContentTypes
- WHERE PubContent.TypeID = PubContentTypes.TypeID
- AND ObjectID = #GetInstances.ObjectID#
- </CFQUERY>
-
- <CFSET CurrObject = StructNew()>
- <CFLOOP QUERY="GetContent">
- <CFSET Temp = StructInsert(CurrObject, TypeName, Data)>
- </CFLOOP>
- <CFSET CurrObject.ClassName = ClassName>
- <CFSET CurrObject.ObjectID = ObjectID>
-
- <CFPARAM NAME="Attributes.ViewMode" DEFAULT="default">
- <CFINCLUDE TEMPLATE="viewmode/#Attributes.ViewMode#.cfm">
-
- </CFLOOP></PRE></BLOCKQUOTE>
-
- <P>Note that this time, the code to render the HTML isn't stored within
- the custom tag itself, but instead in templates in the ViewMode subdirectory.
- Using the ViewMode custom tag attribute, you can choose different templates.
- So if you had a ViewMode/TopStory.cfm template that showed the news item in a larger
- font, you could use the following code:</P>
-
- <BLOCKQUOTE><PRE><CF_ShowContent Location="1" ViewMode="TopStory">
- <CF_ShowContent Location="2"></PRE></BLOCKQUOTE>
-
- <P>For the purposes of this example app, we've only included the default ViewMode;
- the code for it appears below, and should be pretty self-explanatory.</P>
-
- <BLOCKQUOTE><PRE><CFOUTPUT>
- <P><DIV CLASS="HeadlineTeaser">#CurrObject.Headline#<BR></DIV>
- <DIV CLASS="TeaserTeaser">#CurrObject.Teaser#<BR></DIV>
-
- <CFIF CurrObject.ClassName IS 'News Item'>
- <DIV CLASS="LinkTeaser"><A HREF="viewfull.cfm?ObjectID=#CurrObject.ObjectID#">More Info</A></DIV>
- <CFELSEIF CurrObject.ClassName IS 'File with Description'>
- <DIV CLASS="LinkTeaser"><A HREF="binarydata/#Replace(Replace(URLEncodedFormat(CurrObject.File),"%2E",".","ALL"),"+","%20","ALL")#">Download File</A></DIV>
- <CFELSEIF CurrObject.ClassName IS 'Hyperlink'>
- <DIV CLASS="LinkTeaser"><A HREF="#CurrObject.HREF#">Go to page</A></DIV>
- </CFIF>
-
- <!--- If browser is in Admin mode, display editing icons --->
- <CFIF IsDefined("Cookie.PubAdminMode")>
- <A HREF="admin/properties.cfm?ObjectID=#ObjectID#"><IMG SRC="open.gif" WIDTH=16 HEIGHT=14 BORDER=0 ALT="Open" ALIGN="TOP"></A>
- <A HREF="admin/deleteinstance.cfm?InstanceID=#InstanceID#"><IMG SRC="delete.gif" WIDTH=15 HEIGHT=16 BORDER=0 ALT="Delete" ALIGN="TOP"></A>
- </CFIF>
-
- </CFOUTPUT></PRE></BLOCKQUOTE>
-
- <CFSET HREF = "6-learnmore.cfm">
- <CFSET Link = "Learning More">
- <CFINCLUDE TEMPLATE="_footer.cfm">