F.4. Modularization of Embperl Pages
If you are working on a complete site and not just a few pages, there are always elements which occur in every page or in many pages. Instead of copying the source code to every page, you can include Embperl modules in your pages, so you'll have to write the source only once. Such a module could be a header, a footer, a navigation bar, etc. Embperl is capable of not only including such partial pages but also passing arguments. Here is an example that tells the navigation bar which element to highlight:
[- @buttons = ('Index', 'Infos', 'Search') -]
<table><tr><td>
[$if $buttons[$col] eq $param[0]$] <bold> [$endif$]
<a href="[+ $buttons[$col] +].html"> [+ $buttons[$col] +] </a>
[$if $buttons[$col] eq $param[0]$] </bold> [$endif$]
</td></tr></table>
<hr>
Now if you are on the "Infos" page, you can include the navigation bar as follows:
[- Execute ('navbar.html', 'Infos') -]
This will include the navigation bar, which is stored in the file navbar.html, and pass as its first parameter the string Infos. The navigation bar module itself uses a dynamic table to display one column, which contains the text and a link, for every item in the array @buttons. Also, the text that is equal to text passed as a first parameter is displayed in bold. There is also a long form of the Execute call, which allows you to control all aspects of executing the module.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access