Changes between Version 2 and Version 3 of DolphinTutorialMyFirstModule


Ignore:
Timestamp:
Jan 29, 2010, 5:42:53 AM (14 years ago)
Author:
AlexT
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DolphinTutorialMyFirstModule

    v2 v3  
    131131Now we will make some easy modifications to this page. 
    132132But, before proceeding to any modifications, let's disable all template caches in the Dolphin admin panel -> Settings -> Advanced Settings -> Template. It will make life easier by saving some time for you - you don't need to clear the cache manually after each change. 
     133 
     134== 2.1. Change Text == 
     135 
     136This phrase on the page is located in the language file, so all we need is to change the translation. The easiest way is to go to the Dolphin admin panel -> Settings -> Language settings and change the phrase here, but in this case the phrase will not be remembered by our module and this modification would be lost upon module reinstall. To change it in the module forever, we need to edit the '''bloggie/install/langs/en.php''' file. 
     137 
     138File content looks like this (I omitted php tags and copyright info): 
     139 
     140{{{ 
     141$sLangCategory = 'My Bloggie'; 
     142 
     143$aLangContent = array( 
     144    '_me_blgg' => 'My Bloggie', 
     145    '_me_blgg_text' => 'For a community to be whole and healthy, it must be based on people\'s love and concern for each other.', 
     146); 
     147}}} 
     148 
     149The language file is regular php file with one array, where array indexes are language keys and values are translations. Now we need to change the translation only. Take care when editing translations, some characters must be escaped properly as it is a regular php file and regular php string. Also, if you are translating the language file to another language, you need to be sure that you are using UTF-8 encoding during editing of this file. Change it in the following way: 
     150 
     151{{{ 
     152 
     153$sLangCategory = 'My Bloggie'; 
     154 
     155$aLangContent = array( 
     156    '_me_blgg' => 'My Bloggie', 
     157    '_me_blgg_text' => 'Hello World!', 
     158); 
     159}}} 
     160 
     161If you are brave enough you may enter you own text. 
     162 
     163After this change, you will not see the new message on the desired page until you reinstall the module, or you can select the module in the list of installed modules in the Dolphin admin panel -> Tools -> Modules and click Recompile language(s). Now the text is changed on your page, of course, after a page refresh. 
     164 
     165But what is this good for ? A simple text page can be created using an easier method ... you maybe already know that you can create such pages in the Dolphin page builder. 
     166Ok, lets add some dynamics to make a difference from static pages! 
     167 
     168== 2.2. Adding dynamic content. == 
     169 
     170For some users, it maybe useful to see the difference between server time and user time, so this change will show both server and user time. 
     171 
     172It is easier to begin with the things we already know. First we need to add new language keys: 
     173 
     174{{{ 
     175$sLangCategory = 'My Bloggie'; 
     176 
     177$aLangContent = array( 
     178    '_me_blgg' => 'My Bloggie', 
     179    '_me_blgg_server_time' => 'Server time:', 
     180    '_me_blgg_user_time' => 'User time:', 
     181); 
     182}}} 
     183 
     184I assume that you didn't forget to recompile language files for the module after this change! 
     185 
     186Then, we will modify the template file '''bloggie/templates/base/main.html''' from the old one: 
     187 
     188{{{ 
     189<div style="text-align:center;"> 
     190    <bx_text:_me_blgg_text /> 
     191</div> 
     192}}} 
     193 
     194to a new one: 
     195 
     196{{{ 
     197<div style="text-align:center;"> 
     198    <bx_text:_me_blgg_server_time /> __server_time__ 
     199    <br /> 
     200    <bx_text:_me_blgg_user_time /> 
     201    <script type="text/javascript"> 
     202        document.write(new Date()); 
     203    </script> 
     204</div> 
     205}}} 
     206 
     207Some things need clarifying: 
     208 
     209    * '''bx_text''' is a special instruction. It outputs a translation for the key using the currently selected language.   
     210    * '''__server_time__''' is a template variable which is not defined yet. 
     211    * For the user time, we use javascript, because javascript is executed in a browser, on the user side, so the time is user time here. 
     212 
     213Now, try to refresh the page to see what was changed, If everything is done right, you will see something like this: 
     214 
     215{{{ 
     216Server time: __server_time__ 
     217User time: Fri Jan 22 2010 13:46:07 GMT+1100 
     218}}} 
     219 
     220It almost works perfectly. The only thing is the server time display. All the underscores are displayed, because we have not defined a server variable yet. To define this we need to change the following code in the '''bloggie/classes/MeBlggModule.php''' file: 
     221 
     222{{{ 
     223    function actionHome () { 
     224        $this->_oTemplate->pageStart(); 
     225        $aVars = array (); 
     226        echo $this->_oTemplate->parseHtmlByName('main', $aVars); 
     227        $this->_oTemplate->pageCode(_t('_me_blgg'), true); 
     228    } 
     229}}} 
     230 
     231to this one: 
     232 
     233{{{ 
     234    function actionHome () { 
     235        $this->_oTemplate->pageStart(); 
     236        $aVars = array ( 
     237            'server_time' => date('r'), 
     238        ); 
     239        echo $this->_oTemplate->parseHtmlByName('main', $aVars); 
     240        $this->_oTemplate->pageCode(_t('_me_blgg'), true); 
     241    } 
     242}}} 
     243 
     244Before describing all these lines, refresh the page to see the result - Voila! 
     245 
     246{{{ 
     247Server time: Fri, 22 Jan 2010 13:56:54 +1100 
     248User time: Fri Jan 22 2010 13:56:55 GMT+1100 
     249}}} 
     250 
     251The time is almost the same because I'm on a local server and probably you are,too. But in the case of a remote server in another timezone you will see a difference. 
     252 
     253    * '''_oTemplate''' is an automatically defined template class, In our case it is the instance of the '''MeBlggTemplate''' class 
     254    * '''pageStart''' tells you that output will be below 
     255    * '''pageCode''' tells you that output is completed, and the page will be displayed 
     256          o the first parameter is page name, and we take it from the language file using _t function 
     257          o the second parameter tells the script to wrap the output in a box 
     258    * '''parseHtmlByName''' function outputs the '''main.html''' file by making all the substitutions. It accepts the array '''$aVars''' of server variables - in this case we declared the '''server_time''' template variable, which is used in the template as '''__server_time__'''. 
     259 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.
Fork me on GitHub