2

The title of my question seems simple but here is an example of what I want to do:

http://www.mayoclinic.com/health/infant-jaundice/DS00107

What happens on that page is whenever you click on a link to go a section (e.g. "Symptoms") in the article on "Infant Jaundice", it provides a URL parameter like this:

http://www.mayoclinic.com/health/infant-jaundice/DS00107/DSECTION=symptoms

As the DESCTION parameter changes, you get different content on the same page DS00107. The content changes as well as <meta keywords>.

Can someone please tell me how this is achieved? I was thinking it was an if/else situation programmed into the page itself to display different properties depending on the URL parameter. I am using ColdFusion 10 as my web server.

I am not asking what technology to use e.g. AJAX. I don't mind having a page that reloads completely. But where will it get the correct article information from for the various HTML tags and DIVs on the page? Should it be in if/else statements or should it be stored in a database?

I was thinking storing it in a database might be tedious... you would have store all the paragraph and ordered list information in a table. But is it the correct way to do it?

volume one
  • 6,800
  • 13
  • 67
  • 146
  • 1
    Is this already being done through a framework? How are the other pages handling the same issue? – Shawn Jun 25 '13 at 21:42

4 Answers4

1

Well you could try storing your page details:

URL (pointing to the file to include) Page Name etc..

in a db table and then just display the page the corresponds to the url parameter using cfquery.

Ron Rattie
  • 71
  • 1
1

What you’re seeing is URL rewriting. This can be done within the web server, not necisarlay with in ColdFusion/PHP ext. What the web server will do is rewrite the url mayoclinic.com/health/infant-jaundice/DS00107/DSECTION=symptoms to a link something like: mayoclinic.com/health/infant-jaundice/DS00107/index.cfm?DSECTION=symptoms.

For displaying the content with in the page, I would use as switch statment vs. using a series of if/else’s if you have more then 2-3 possible displays. You can use as many case blocks as needed.

<cfswitch expression=”#url.DSECTION#>
    <cfcase value="symptoms">  
        <!---   symptoms code / html here --->
    </cfcase>
    <cfcase value="causes">  
        <!---   causes code / html here --->
    </cfcase>
    <cfdefaultcase>
        <!---   default code / html here --->
    </cfdefaultcase>
</cfswitch>

This is a very simple example, to illustrate the idea of URL rewriting.

Addition:

I was wondering if perhaps they were using a database query rather than if/else statements?

Yes you could.For a query driven results you could do something like:

<cfquery name="pageContent" datasource="yourDatasource">
    SELECT htmlText 
    FROM pages
    WHERE page = 'dir/index.cfm'
    AND content <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.DSECTION#">
</cfquery>
<cfoutput>#pageContent.htmlText[1]#</cfoutput>

If the content is static, and rarely updated, another option would be to look into includes and try to leverage the ability to execute code based on the content.

<cfinclude template="./includes/symtoms.cfm"> or <cfinclude template="./includes/#url.DSECTION#.cfm">
Twillen
  • 1,458
  • 15
  • 22
  • in your opinion is using cfswitch to conditionally output article-style information to a page better than storing the article in a database? do you think this is how the mayoclinic are doing it? – volume one Jun 25 '13 at 20:11
  • I saw your comment to Srini after I fist posted. I've added additional options. I haven't fully played with the variable in the template path, but my one test did pass. – Twillen Jun 25 '13 at 20:18
  • Is this how the mayoclinic doing it; I would make a strong guess that they are pulling their content out of a database. For SEO likes like these, you could look at WordPress and see how they leverage URL rewriting. I know WordPress keeps all of the content in the database. – Twillen Jun 25 '13 at 20:36
0

For most graceful behavior, you would want to do this with a server side scripting language like JSP/PHP.

Srini
  • 37
  • 1
  • Yes I can do if/else statements in ColdFusion. But is it the way its done? I would end up having about 10 if/else statements for each HTML tag on the page to ensure it displays the correct information for each page. I was wondering if perhaps they were using a database query rather than if/else statements? – volume one Jun 25 '13 at 14:41
0

This can be done using Ajax with any serverSide programming techniques such as Servlets ,Spring MVC or PHP.In Ajax the whole page doesn't load by clicking the url we can define what part of the page should be reloded for example consider the google map on a page when you drag or zoom or do any other mouse events a action arises and sends to server it recieves the data from server and changes only some part of the page instead of reloading the whole page.

Rahul Bussa
  • 258
  • 1
  • 3
  • 14