Using path placeholders in collect data actions, you can easily compile indices of files.
Let’s say you are developing a web site in PHP. You keep all the main PHP files in a separate folder. Now, you want to create a navigation bar in PHP. While you could do this by hand, automating this in PowerGREP will save you a lot of time, certainly if pages are frequently added and removed. Though I am using PHP in this example, the same principles apply to any other web scripting language.
The final PHP file should look like this, with the complete if statement repeated for every main page on the site:
function navbar($mainpage) { if ('currentpage' == $mainpage) { print '<B>currentpagetitle</B><BR>'; } else { print '<A HREF="currentpage">currentpagetitle</A><BR>'; } }
Obviously a very simple navigation bar, but good enough to illustrate the idea.
# \1 if ('%FILENAME%' == $mainpage) { print '<B>\1</B><BR>'; } else { print '<A HREF="%FILENAME%">\1</A><BR>'; }
Two techniques make this action work. The regular expression that searches for the title tag captures its contents into a backreference \1 which we use to insert the title into the collected data three times. The path placeholder %FILENAME% inserts the name of the file being searched through into the collected data. This example assumes that all HTML files are in the same folder. If not, you’ll need to use another path placeholder. The finishing touch is to use the headers and footers option in PowerGREP to wrap our PHP code into a complete PHP function.
You can find this action in the PowerGREP5.pgl standard library as “Generate a PHP navigation bar”.
All that is left to do now is to include a reference to the navigation bar in each of the web pages, something you can also easily do with PowerGREP.