ASPCompiler OnProcessFile
ASP Compiler 1.1 documentation is under development. See also the examples.


Function OnProcessFile( fileRelativeName )

fileRelativeName parameter is the relative file path and name relative to the site root (as defined in the project settings). It iw without "\" in the beginning. 

Return value:  The function should return:

Modified or the same relative file path and name if the file is to be processed

Empty string if the file must not be processed.

function  OnProcessFile( fileRelativeName )


Dim numFile
numFile = 0
Function OnProcessFile(fileRelName)
  numFile = numFile + 1
  If numFile <= 10 Then
    OnProcessFile = Info("FileRelativePath") & "\" & _
        Info("FileNameOnly") & numFile & "." & Info("FileExtension")  
    OnProcessFile = ""
  End If
End Function

This will cause the file to be processed 10 times and the resulting files will be named with numeric suffixes corresponding to the iteration number (suppose, for example, you have exactly 10 different things to put in 10 versions of a file based on a template HTML file).


If you need the file to be processed once as is default and there is no need to change its name you do not need to handle this event. Such a code will only duplicate the default behavior.

As the sample above shows the event handling routine is responsible for two things - number of iterations (how much times the file will be processed) and also for the file name selection. Usually repeating the file several times will mean generation of set of files based on this one. Thus naming is important and also it concerns the links in those files and probably other files in the project. Thus the file selection is to be done by the CTS. To aid the script, compiler supplies the elements of its name and path through the Info collection. The script cold easily construct a name by combining the parts adding numbers as suffixes/prefixes and may be subdirectories to the relative file path.

Note that the received path in the parameter and the returned value are relative path and file names! If the project's source root path is c:\project\src and output (compiled) path is c:\project\compiled and the processed file is in a subdirectory - c:\project\src\dir1\file.htm the event's parameter will be "dir1\file.htm". The script must return relative path too - for example it could return dir1\file1.htm, dir1\file2.htm and so on. When generating many files from a single file in the project you are not limited to suffixes and prefixes of the file name - you may choose to return for example - dir1/1/file1.htm, dir1/2/file.htm etc. The naming depends only on your site structure and organization of the links between the pages.

Usually the CTS that generates multiply pages based on single file from the project also generates some of the links in them (See also the ASPC examples). This could be done using CUSTOM tags or modifying <A HREF ...> tags. In the second case you will need to handle the OnModifyParser event and request certain A tags to be included in the document tree. If are not sure what method is better for your case a good general rule applicable for many case could be defined - if the cross-links that must be generated are many (tens or more on the page) parsing A tags will be better - if the cross-links are few it is often convenient to construct them in turn - by replacing single CUSTOM tag with 2-3 links thus CUSTOM tags will need less efforts. Usually the cross-links are not too much (typically they define the navigation between the generated set of pages and no more than one or two other sets that are also generated). The resting links are general links to outside resources or to other parts of the site and could be specified as full URL or as virtual path in the site (e.g. /news/index.htm). If you choose to parse the A tags we recommend you to use some kind of "indicator" for the links that must be generated. This could be ID attribute - it will define their name in the document tree and make them easy to find, or you can add a custom attribute and set-up parser during the OnModifyParser event to parse only the A tags containing the attribute. Copyright 2001-2006 newObjects [ ]