Including Other HTML Documents
[Previous] [Main] [Next]

 
It's often convenient to use existing HTML documents within an html++ application. A typical approach is to use a third-party WYSIWIG design tool (such as Microsoft FrontPage) to create headers, footers, or forms. Such documents can be easily included in html++ output, having the benefit of being able to be modified without recompiling the application.  
 
Example
 
#include <stdio.h>  
#include <stdlib.h>  
#include <dcmicro/htmlpp/htmlpp.h>  
 
//  Load an HTML document into an object  
htmlGroup& IncludeHTML  
(  
   htmlGroup& group,  //  container object  
   char * filename    //  filename to load  
)  
{  
  FILE * file ;  
  char   line_data[ 300 ] ;  //  increase as necessary  
  String str ;  
 
  //  open the specified text file  
  file = fopen( filename, "rt" ) ;  
  if ( file != (FILE *) NULL )  
  {  
     //  loop for all lines in the file  
     while (  
        fgets( line_data, sizeof(line_data), file ) != NULL  
           )  
     {  
      str = line_data ;  
      str.ToUpper() ;  
 
        if ( str.Contains("HTML>")   
             || str.Contains("HEAD>")   
             || str.Contains("<BODY")  
             || str.Contains("TITLE>")   
             || str.Contains("BODY>") )  
        {  
           //  Don't include lines containing  
           //  keywords relating to the page.  
        }  
        else  
        {  
           //  Store the line as a literal to avoid  
           //  translation of symbols when output.  
      group << htmlLiteral( line_data ) ;  
        }  
     }  
 
     fclose( file ) ;  
  }  
 
  return group ;  
}  
 
 
int main( void )  
{  
   htmlCgi   server ;  
   htmlPage  page( "html++ test app" ) ;  
 
   //  Load the header document (it is assumed to exist)  
   htmlContainer   header ;  
   IncludeHTML( header, "/home/templates/header.html" ) ;  
 
   //  Load the footer document  
   htmlContainer   footer ;  
   IncludeHTML( footer, "/home/templates/footer.html" ) ;  
 
   //  Construct the page, inserting the header  
   //  and footer HTML documents around the text.  
   page << header  
        << htmlHorizontalRule()  
        << "This is a test of using htmlContainer to "  
           "include existing header and footer documents."  
        << htmlHorizontalRule()  
        << footer ;  
 
   server << page ;  
   return 0 ;  
}  
 


©1998 DC Micro Development. All rights reserved.
No portion of this document may be c opied or reproduced without expressed written consent.
html++ is a trademark of DC Micro Development.