using asp- or php-style "includes" in ActiveVFP

Topics: Developer Forum
Mar 4, 2011 at 10:25 PM

The #include directive is a key benefit of using an .asp or .php extension instead of .htm or .html for your HTML-coded
pages.  The #include directive lets you fetch blocks of code inside "include" files that commonly use a .inc extension and
are kept in a separate  \includes folder.

Here's some w3School discussion of #include: http://www.w3schools.com/asp/asp_incfiles.asp

In my own HTML page (which has an .asp extension) is the following #include call to fetch my left navigation block:

<!-- #include file="includes\leftnav.inc" -->

And here is the code in the leftnav.inc file being fetched.

<h2>Main Navigation</h2>
<ul>
<li><a href="default.asp"          >Home</a>/li>
<li><a href="author_index.asp" >Expert Interviews</a></li>
<li><a href="events.asp"          >Events Calendar</a></li>
</ul>

OK, here's the issue.   On the website where I have AVFP installed, I can use the #include directive without 
trouble.  And it's real handy for maintenance because if I have a global change to make in my left navigation
bar, I can make that change in one .inc file.

However I could not get the #include directive to work inside the HTML templates folder of my AVFP virtual folder.
Is it possible to use?    Has anyone found a way to take advantage of #include's power within AVFP?

Coordinator
Mar 5, 2011 at 12:26 PM

Well this turns out to be so simple, it's stupid!!

1.)  Put this function with the other ones at the bottom of Main.prg:

************************************************************************
* Include
*********************************
*** Function: Include an HTML file as part of the output
************************************************************************
FUNCTION include
LPARAMETERS lcHTMLfile
lcHTMLout= FILETOSTR(oProp.HTMLpath+lcHTMLfile)
RETURN oHTML.mergescript(lcHTMLout)
************************************************************************

2.)  Create and save the Header.htm file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>This is my standard header!!</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
</HEAD>


**Note the use of   content="text/html; charset=windows-1252">
This solves the squiggly character problem at the top of the page

3.)  Put this in your regular HTML files:

 

<%= include("header.htm") %>
<BODY  bgColor=#1d5090 leftMargin=0 topMargin=0 marginwidth="0"
marginheight="0">
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
    <TD vAlign=bottom width="100%" bgColor=#1D5090>
      &nbsp;</TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
    <TD width="100%">

4.) Let me know how this works for you. It seems to solve your problem with Style Sheets perfectly, no?

Mar 5, 2011 at 8:13 PM

Now why didn't I think of that.   Create an AVFP function to provide #include functionality.  It may be simple, but it's also
brilliant.   Thanks.