Below are some examples of EWD pages that make a call to a pre-page script. The reference to the pre-page script is in the ewd:config tag. The pre-page script is invoked before the page (or fragment) is rendered and is used to fetch data from the back-end database and prepare it ready for use within the associated page, typically by mapping the fetched data to EWD Session variables and/or arrays.

The first example shows a page that calls a Caché class method as a pre-page script

  <ewd:config isFirstPage="false" prePageScript="##class(ewd.test).getMyData">
  <html>
   <head>
    <title>EWD Page with a Pre-page Script</title>
   </head>
   <body>
     <div>Example value = <?= #myExample ?></div>
   </body>
  </html>

Here's an example of a simple Caché class method pre-page script. A pre-page script has a single input parameter (sessid) and normally returns a null value. The variable sessid uniquely identifies the user's session and is passed to your pre-page script automatically by EWD at run-time. Most of EWD's API methods require the sessid to be passed into them, as shown in the example which sets the session variable myExample:

ClassMethod getMyData(sessid As %String) As %String
{
 d setSessionValue^%zewdAPI("myExample","Hello World!",sessid)
 QUIT ""
}

The second example shows a page that calls a Caché extrinsic function as a pre-page script

  <ewd:config isFirstPage="false" prePageScript="getMyData^myExampleScripts">
  <html>
   <head>
    <title>EWD Page with a Pre-page Script</title>
   </head>
   <body>
     <div>Example value = <?= #myExample ?></div>
   </body>
  </html>

Here's an example of a simple Caché extrinsic function pre-page script (assumed to be part of the routine ^myExampleScripts). A pre-page script has a single input parameter (sessid) and normally returns a null value. The variable sessid uniquely identifies the user's session and is passed to your pre-page script automatically by EWD at run-time. Most of EWD's API methods require the sessid to be passed into them, as shown in the example which sets the session variable myExample:

getMyData(sessid)
 d setSessionValue^%zewdAPI("myExample","Hello World!",sessid)
 QUIT ""

The third example shows a page that calls a PHP function as a pre-page script (Note you must specifically configure EWD to allow you to use this feature). The PHP function is embedded anywhere within the EWD page. The input parameters ($ewd_session and $connection) are mandatory and are automatically passed to the function by EWD at run-time. A pre-page function normally returns a null value

  <ewd:config isFirstPage="false" prePageScript="getMyData">
  <script language="php">
    function getMyData($ewd_session, $connection) {
      setSessionValue('myExample','Hello World!',&$ewd_session) ;
      return '' ;
    }
  </script>
  <html>
   <head>
    <title>EWD Page with a Pre-page Script</title>
   </head>
   <body>
     <div>Example value = <?= #myExample ?></div>
   </body>
  </html>