Question

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?

Was it helpful?

Solution

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">

OTHER TIPS

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.

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top