Have you ever encountered situations where you want to display the announcements for all of your users in all pages of your website that created with PHPMaker? Well, I have. So I created the following modification by customizing the template in order to implement it each time I generate my website using PHPMaker. Now you can display your announcements easily by setting it up the related constant in your configuration file. Besides that, you have to define the announcement itself from the .xml language files for the content of the announcement. Why must we define it in .xml language file? Because it has to support for multi language, right?
This announcement feature is very useful to broadcast some important information that need to be known by all of your users. By using this customization, you will know how to create the new constants and using it for all pages. Also, you will know how to create a user-defined style into your .css file according to the style or theme you are using for your website. Lastly, you will know how to implement the global code inside the PHPMaker application that will be used in all of your pages.
All we have to do is customizing PHPMaker template files and adding some code into Server Events section of PHPMaker. In other words, we will not modify the generated script files.
Please click on the following image to watch the demo:
[hidepost]
-
Open your ewcfg.php file, and find this code:
// General
before that line, insert this following code:
// Begin of modification by Masino Sinaga, for Announcement in all pages, August 30, 2011 define("EW_SHOW_ANNOUNCEMENT", FALSE, TRUE); // Announcement status, set the second parameter to TRUE to show the announcement in all pages. define("EW_ANNOUNCEMENT_TEXT", "", TRUE); // Announcement text, the value is derived from the .xml languages files // End of modification by Masino Sinaga, for Announcement in all pages, August 30, 2011
-
Open your C:\Program Files\PHPMaker8\languages\english.xml file, and find this code:
</global>
before that line, insert this following code:
<phrase id="AnnouncementText" value="This is the announcement number one. <br />This is the announcement number two."/>
Do the same way with your another .xml language file. For example, I am also using Indonesian language, so I add those phrases to my indonesian.xml file:
<phrase id="AnnouncementText" value="Ini merupakan pengumuman yang pertama. <br />Sedangkan yang ini adalah pengumuman yang kedua."/>
-
Open your template.php file, and find this code:
<!--##=SYSTEMFUNCTIONS.CSSFile##-->
before that line, insert this following code:
<?php if (EW_SHOW_ANNOUNCEMENT==TRUE) { ?> <?php if (EW_ANNOUNCEMENT_TEXT!="") { ?> <span class="ewMessage"><?php echo EW_ANNOUNCEMENT_TEXT; ?></span> <?php } ?> <?php } ?>
-
Next, go to your PHPMaker application, and click on HTML tab, then click on Styles sub-tab, and then click on the Edit styles button, and there will be a CSS Editor window appears. Scroll down the textbox area to the bottom, and you will find this code:
/*END_USER_STYLES*/
before that line, insert this following code:
.ewMessage { color: inherit; font-family: Tahoma; font-size: 8pt; padding: 0.5em; border-left: 1px solid #7EACB1; border-right: 1px solid #7EACB1; border-top: 1px solid #7EACB1; border-bottom: 1px solid #7EACB1; display: block; }
-
Next step, still on your PHPMaker application, click on one of your tables from the left panel, and see in the right panel of your PHPMaker application, there are two tabs appear. They are: Fields and Server Events/Client Scripts. Click on the Server Events/Client Scripts tab, and then click on Server Events -> Global -> All Pages -> Page_Loading.
Find this code:function Page_Loading() {
make sure after that line, you have already this following code (if they are not there, just add it now):
global $Security; global $Language;
Afterwards, copy and paste this following code inside the Page_Loading function, just before the last closing bracket of that function:
if (EW_SHOW_ANNOUNCEMENT) { @define("EW_ANNOUNCEMENT_TEXT", ew_JsEncode($Language->Phrase("AnnouncementText")).' ', FALSE); }
[/hidepost]
Leave a Reply
You must be logged in to post a comment.