3 Replies Latest reply on May 18, 2010 7:10 AM by ilssac

    Replace special codes on Page Render

    Bump_21_Design

      Hey all - I'm new the the forums here, so HELLO! I look forward to  being part of the community and helping out as much as I can, but as  with all new members, I come with a problem that needs solving...

       

      I'm  working with complex dynamic template files and, in an effort to  simplify the template-building process and boost the efficiency of our  system, I am looking for a way to replace something like a special  character code to include a pre-defined construct.

       

      For  example - I have a template file that looks like this (simplified):

       

      <html>

      <head>

          <link rel="stylesheet" type="text/css" href="styles/myStyles.css">

      </head>

      <body>

       

      <div  id="welcome">

          Welcome to my Page!

      </div>

       

      <div  id="navigation">

          <cfinclude template="../rootFiles/builder_navigation.cfm">

      </div>

       

      </body>

      </html>

       

      The actual templates are much more complicated than this, but this should be enough for the purposes of demonstration.  I am looking for a way to call (for example) my '../rootFiles/builder_navigation.cfm" -- I have two main fuctions the template serves, to represent itself for a builder as well as serve as a template for a publishing script. So, with this in mind, if I am using the builder, I need to call 'builder_navigation.cfm' but if I am publishing the template i need to call 'publish_navigation.cfm.'

       

      So, the above script  would be used for the builder, and the below script would be used when a  publish is called...

       

      <html>

      <head>

          <link rel="stylesheet"  type="text/css" href="styles/myStyles.css">

      </head>

      <body>

       

      <div   id="welcome">

          Welcome to my Page!

      </div>

       

      <div   id="navigation">

          <cfinclude  template="../rootFiles/publish_navigation.cfm">

      </div>

       

      </body>

      </html>

       

      What I am hoping is that I can use a template file like the one below to dynamically call (through a CFINCLUDE) either the publish navigation script or the builder navigation script by using one 'keyword' or 'special code'

       

       

      <html>

      <head>

          <link rel="stylesheet"  type="text/css" href="styles/myStyles.css">

      </head>

      <body>

       

      <div   id="welcome">

          Welcome to my Page!

      </div>

       

      <div   id="navigation">

          [TEMPLATE_NAVIGATION]

      </div>

       

      </body>

      </html>

       

      This way I can use the same file and call the appropriate navigation template depending on the need. I would use a simple <cfif> statement to determine which I need, but I need to keep this as plain HTML as I can as when the publish scripts are called I need plain HTML as the variables that would be needed by the <cfif> script would not exist after the published template has been created.

       

      Thanks  in advance!

        • 1. Re: Replace special codes on Page Render
          ilssac Level 5

          I'm sorry, after all that I am not sure what you are asking?

           

          I can think of a couple of ideas for what I think you are trying to do.  But I'm uncertain on how much effort to expend before I understand what you really are trying to figure out.

           

          You may want to look at the onRequest(), onRequestStart() and onRequestEnd() methods of an Application.cfc file.  These methods, particularly the onRequest(), can allow you to apply a post render process to the response stream before it is returned to the client browser.

           

          You may also want to look at some inteligence that might be able to be put into your template pieces.  So that they can determine how to render the content based on some type of data.

           

          Thirdly you may want to look at custom tags which are more intelligent then straight forward includes.  You can create parameters and attributes that influence how the custom tag returns its results.

          • 2. Re: Replace special codes on Page Render
            Bump_21_Design Level 1

            I'm sorry for the murkiness - let me clarify:

             

            I have an HTML editor that resides within a template file (visual template) - a user can alter the content, create new content, etc.  The user is allowed to choose the template file which to use.

             

            When they are finished they can publish to an HTML/Java/CSS file (full website).  I would like to use the same template file for both the editor/builder as well as the publish script.

             

            Only minor changes are needed between the two as present - the first chunk of code in my original represents file1 - the file that is called for the editor.

            The second chunk of code in origninal post represents file2 - the file that is called when the publish script is activated.

             

            The thrid chunk of code in the original post is what I would like to create -

             

            So i would like to have the section of code like this:

             

            <div id="navigation">

              [TEMPLATE_NAVIGATION]

            </div>

             

            and replace the "[TEMPLATE_NAVIGATION]" on call with the proper <cfinclude> template. I can think of several solutions for this such as setting the include file as a variable in a different script or using CFIF, but if I could do it this way, it will greatly simplify the process by which I can build and install new templates into the system.

             

            This would also allow me to update the system and its file structure (which is done frequently) without having to edit every template file as well.

             

            Please let me know if I am still not being clear enough and thank you for your prompt response!

            • 3. Re: Replace special codes on Page Render
              ilssac Level 5

              You still haven't clearly designated when and where you would like the token replaced.

               

              The best suggestion I can make at this time is to look at the onRequest() method of the Application.cfc file.  It would allow you to find a token like that and replace it with other content before the response if sent to the browser.