Smarty cleverly handles the content page code in iframe _ php skills

Source: Internet
Author: User
Recently I am using smarty for a small project and found that the template engine in smarty is quite good, so that the real separation between the front-end and the back-end is not much nonsense.
I should know that iframe is often used to process navigation. it is quite simple to do this function according to the general idea.
However, when I used smarty, I found the problem. for example, an iframeset is divided into: top header, menu on the left, main on the right,
In normal cases, if smarty is used for processing, it is generally like this:
If the three pages are only static pages, they are processed as follows:
Iframe.html code:

The code is as follows:








Suppose that the content pages in iframe must be applied to some special processing, such:
Top.html needs to display the background login username
In menu.html, menus are dynamically obtained.
Main.html needs to read server information
In this way, we will use three background processing pages for the three content pages respectively.

The code is as follows:


// Top. php:
$ Smarty-> assign ('user', $ names );
Smarty_Output ('Top. php ')
// Menu. php:
$ Arr = array ();
$ Arr = GetMenu ();
$ Smarty-> assign ('menu ', $ arr );
Smarty_Output ('menu. php ');
// Main. php
$ Smarty-> assign ('serverinfo', $ serverInfoArr );
Smarty_Output ('main. php ');
// Display the iframe page
Smarty_Output('iframe.html ')


The above processing method can fully meet the requirements
Iframe.html code:

The code is as follows:








Now let's assume that we want to divide the three content pages into roles. different roles and three pages need different effects.
According to the above processing method, we need to process three pages separately, so we naturally have more redundant processing, and the maintenance will be troublesome in the future.
So I thought of the following method, and developed a dedicated processing program iframe. php, simulating the above three pages through conditions.
Directly paste the code:
Iframe. php background code:

The code is as follows:


/* Put the shared processing code here */
Switch ($ src)
{
Case "top ":
/* Put the processing code here */
Smarty_Output('top.html ');
Break;
Case "menu ":
/* Put the processing code here */
Smarty_Output('menu.html ');
Break;
Case "main ":
/* Put the processing code here */
Smarty_Output('main.html ');
Break;
Default:
Break;
}


Iframe.html:

The code is as follows:








Through this process, I feel much more convenient.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.