1

Topic: How to use PHP in a Dynamic Include

If you type plain text, the plain text will replace the DI in your pages.

If you put a php script into the DI, whatever you echo out will replace the DI in your pages.

Also, when using a php script, any #vars# you set active for the DI are presented as php variables.

Here's an example of php use when you have set a #city# var active for a DI:

<?php
$city_t = ucwords(strtolower($city)); // make a titlecase city variable
echo "I live in the city of $city_t.";
?>

Of course this is a simple example. You can do most anything with your php script. Retrieve data from a database. Read files etc.

Anything you echo out of the script will be placed into your DI in your pages.

2 (edited by CybrPimp 2021-07-20 06:03 pm)

Re: How to use PHP in a Dynamic Include

Hey Larry,

What would you recommend in the case where a Dynamic Include has a long lifecycle.

So for example in the case where the first time the DI was run the PHP script would launch an external BPM process to produce the page content.  First it could auto generate the content, then it could be optimized using more onpage data like Cora or Surfer, then manual tasks for review and approval.

Once approved in the external BPM process the data would be ready in the database so the next time the DI was called, it could return the complete page content.

The BPM process would have automated tasks but also some manual user tasks and so it could take a few days for the actual process to be completed and the page content to be done.

Ideally, every time we rerun the build the DI data could be refreshed?

Does this make sense?

3

Re: How to use PHP in a Dynamic Include

CybrPimp wrote:

What would you recommend in the case where a Dynamic Include has a long lifecycle.

Every time a page is accessed, all of it's DI's are run. To control differing DI behavior each time, use a "status" file.

When your DI script runs, it can read the status file to determine how to proceed.

For example...

If the DI sees the status file does not exist, your script would do the following:

1. Create a status file containing "init".
2. Start the long task.
3. Return blank or whatever you want to the visitor.

If the DI reads "init", it will echo back blank or nothing.

When the long process completes, the long process would write "ok" into the status file.

When the DI runs again, it reads the "ok" and outputs the page you created and changes the status as needed.