in the previous article, we have brought the overall framework of ecshop. From the overall view of the ecshop, I believe that everyone's thinking should be very clear. As a modification to the open source project you, can have a preliminary understanding of the ecshop, I will give you the following I am in the process of revising ecshop some experience.
Let's talk about the template according to Ecshop. When it comes to templates, this is the main file that the Ecshop front desk displays, and if you can understand theme template files and style sheet files, there should be no problem with the Ecshop foreground display. How is the page in Ecshop displayed? Let's put aside this question first, let's look at how Ecshop is reading a series of data from the database and uploading it to the display page. To solve this problem, we need to useindex.dwt under index.php and Theme/default in the root directoryas a use case. The corresponding two folders are used becauseThe data to be displayed in INDEX.DWT is loaded through Smarty from the index.php .. The following code is in the index.php:
$position = assign_ur_here();
$smarty->assign(‘page_title‘, $position[‘title‘]); // 页面标题
$smarty->assign(‘ur_here‘, $position[‘ur_here‘]); // 当前位置
First it is called the function assign_ur_here, so that the variable $position, in the variable $position has the title and Ur_here these two variables. The following code will be in the INDEX.DWT:
<title>{$page_title}<title>
Yes, once $smarty->assign (' Page_title ', $position [' title ') is executed, the $page _title becomes a variable that can be used in INDEX.DWT. So far we know how to pass the variables we need from the PHP script to the DWT file. Smarty is the mechanism by which the content that needs to be displayed is uploaded to the corresponding DWT file, thus separating the page from the content. The data in the PHP script is already available in the DWT file, and the following is how to display the data. Any variable loaded into a DWT file by Smarty is displayed with {} or <!--{}-->. If an array is loaded then it is shown by the Smarty loop, and if I pass in an array that is $school and has name in each entry in the array, the following code is the name of each entry that implements the array to display in the page.
Foreach($school as $k) {
echo $k[‘name’] . ‘ ’;
}
This will print out all the contents of the array in the page.
Let's give an example to illustrate how the DWT is displayed.
Write Smarty->assign (' Test ', ' This is just a test! ') somewhere in the index.php;
Then write {$test} somewhere in the INDEX.DWT, and there will be "this is a test!" in the home page. Of course it shows where it's related to where you put {$test}. Of course, this position is a rule, the DWT is not any place can be edited, some places are not moving, these we will be in the back of one by one to explain. At this time if you do not appear in your home page "This is a test!" This content, then you also do not worry, because the default cache in the Ecshop is open, can not display the cache is definitely the problem, this we will also give explanations. Today we are discussing how to transfer parameters and parameters to a DWT. The next one will explain the above-mentioned problems, Thanks.
Next day
Hello everyone, today we will solve the problem left over from the last. The last time we talked about how to transfer parameters from a PHP script to a DWT template, we left two questions, the first is that some places in the DWT are not editable, and the second is to pass parameters to the DWT and let it show, it doesn't necessarily show up.
first of all, let's discuss the first question-why there are places where you can't edit. We analyzed the cause of the problem by discussing INDEX.DWT. In the index.dwt we will see a lot of statements like this.
If you have a little knowledge of the backstage management of the ecshop, the words "left area" should be familiar to the people! Yes, in the background template management--settings template you will see the following picture:
on the surface, it should be known that the "Commodity Classification tree" is displayed in the middle area of the entire page. So why in the background to re-select and OK, the page display will follow your choice to display it? The essence of it is this, each of the above modules is corresponding to a library file (that is, theme under the library under the LBi file), when you put the above these according to your layout settings and click OK, The program will write the contents of each LBI file into the INDEX.DWT according to your layout choice, then the contents of the LBi file to write, this time the above sentence will play a role, such as the above "sales line" is the right area of choice, Then when you are sure, the program will rewrite the INDEX.DWT , where the "sales line" corresponding to the LBI (that is top10.lbi) content will be fully read and written to INDEX.DWT and between. So this time you may have a question, if there is a lot of content to go to the right area to write, which first write it? There is a "serial number" in the diagram above, which is the order in which you decide to write. Here is a snippet of code between and in the index.dwt file after writing:
<div class="box">
<div class="box_2">
<div class="top10Tit"></div>
<div class="top10List">
<ul>
<li>
src="../images/top_{$smarty.foreach.top_goods.iteration}.gif">
<a title="{$goods.name|escape:html}" href="{$goods.url}">{$goods.short_name}<a>
<li>
<ul>
</div>
</div>
</div>
<div class="blank5"></div>
OK, here I believe you should know a lot, then why in the index.dwt some of the places are not editable. People think of the above code is from which side, right, is read from the Top10.lbi, and then write here, if you edit here, and then the next time re-layout, the content is not to be rewritten out of it! So in index.dwt similar and between the content is dynamically generated, is not editable, if you really want to edit this side of the content, then edit the corresponding LBI file.
I believe you already know why some parts of DWT files are not editable. So today we'll talk about this, and next time we'll look at the cache problem. I feel this is a headache (if you add a session yourself).
Third Day
The last time we discussed the problem of the template, we left a question--cache. I think this problem should not be discussed in the present position, and then we will analyze the problem. By now we know some of the template's operations, but we are still depressed because we are only under the control of the Ecshop's foreground frame. So how can we get out of it? If we can do our own to add to their own or can put the things we want to put the template, then it should be a higher step to see Ecshop.
To be able to add a template, you must do the foreground can display the template, the background can edit the template. Let's step-by-step to teach you how to add a template that belongs to you.
Before we add a little bit of analysis, for a template, in the foreground must have a PHP file and it corresponds (it is obvious that this PHP file is implemented to the template file transfer data). And in the background can edit the template for the module, that is, in the template management-set the template has the template you add options.
Let's add a home template below. Start by creating new HOME.DWT and home.php in the root directory. The contents of INDEX.DWT and index.php are then copied to HOME.DWT and home.php respectively. The content of this template is entirely up to you, and your content will determine how you want to modify HOME.DWT and home.php. Of course, the content of this template is limited, first of all, the Home Template candidate library files are present. What does this mean? This means that for each template file, the library files that can be called are fixed, and the library files that can be called are defined in the file admin/includes/lib_templete.php. First of all in the background to put home this template into the template can be set content, some of the code is as follows:
/* 可以设置内容的模板 */
$template_files = array(
‘home.dwt‘,
‘index.dwt‘,
‘zhiku.dwt‘,
‘article.dwt‘,
‘article_cat.dwt‘,
‘brand.dwt‘,
‘category.dwt‘,
‘user_clips.dwt‘,
‘compare.dwt‘,
‘gallery.dwt‘,
In the code above, HOME.DWT is added to the editable template in the background, and you can edit the home template in the template management settings template in the background. But here we find a very small problem, that is the home template in the background is displayed in what name. In fact this is very simple, as long as the file language/zh_cn/admin/template.php add $_lang[' template_files ' [' home '] = ' home template '; Then the name of the home template you see in the background is the "home template", and of course it can be set to another name. In the above we have said that each template can be called the library file is fixed, since it is fixed, which should be? Take index for example, in the file admin/includes/lib_templete.php has the following code:
‘index‘ => array(
‘/library/ur_here.lbi‘ => 0,
‘/library/search_form.lbi‘ => 0,
‘/library/member.lbi‘ => 0,
‘/library/new_articles.lbi‘ => 0,
‘/library/success_article.lbi‘ => 0,
‘/library/dynamic_article.lbi‘ => 0,
‘/library/school_article.lbi‘ => 0,
‘/library/category_tree.lbi‘ => 0,
‘/library/top10.lbi‘ => 0,
‘/library/invoice_query.lbi‘ => 0,
‘/library/recommend_best.lbi‘ => 3,
‘/library/recommend_new.lbi‘ => 3,
‘/library/recommend_hot.lbi‘ => 3,
‘/library/recommend_promotion.lbi‘ => 4,
‘/library/group_buy.lbi‘ => 3,
‘/library/auction.lbi‘ => 3,
‘/library/brands.lbi‘ => 0,
‘/library/promotion_info.lbi‘ => 0,
‘/library/cart.lbi‘ => 0,
‘/library/order_query.lbi‘ => 0,
‘/library/email_list.lbi‘ => 0,
‘/library/vote_list.lbi‘ => 0 ),
then the library file that this side enumerates to can be called for INDEX.DWT. According to gourd painting scoop, home.dwt need to call which library files, then the corresponding above this write is, I believe everyone has this level. OK, so far a template file has been added successfully, then its display in the browser will be determined by the background settings template. OK, add a template of your own I'll talk about it here, and we'll go on to discuss ecshop in the next issue. thanks!!!
From for notes (Wiz)
Modify Ecshop Template Experience