Include a PHP Navigation Bar
The previous example showed you how to generate a php navigation bar. This example shows you how to include a reference to the navigation bar in each of the PHP files.
- Unless you still have the files for creating the navigation bar marked in the File Selector, mark the files you want to add the navigation bar to.
- Start with a fresh action.
- Set the action type to "search and replace". Leave the search type as "regular expression".
- In the Search box, enter the regular expression </h1> and make sure to leave "case sensitive search" off.
- Enter \0<? requires('navbar.php'); navbar('%FILENAME%'); ?> as the replacement text. You will probably also want to press Enter after the \0 to insert a line break into the replacement text, so the navbar stuff ends up on its own line, rather than after the </H1>.
- Set the target and backup file options as you like them.
- Click the Preview button to run a test.
- If all looks well, click the Replace button to add the navigation bar reference to each file.
When PowerGREP find a match in c:\web\source\index.php, then the replacement text will become <H1><? requires('navbar.php'); navbar('index.html'); ?>. Whether your site consists of just a dozen or thousands of pages, inserting the reference with PowerGREP is easy and saves you a lot of time. Not to mention the potential errors if you have to type in the file names manually into each file.
You can find this action in the PowerGREP5.pgl standard library as "Include a PHP navigation bar".