Smarty cleverly handles the Content Page code in iframe

Source: Internet
Author: User

Not much nonsense. Go into the subject
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: Copy codeThe Code is as follows: <frame src = "top.html" name = "topFrame" id = "topFrame" scrolling = "no">
<Frameset cols = "180, *" name = "btFrame" id = "btFrame" frameborder = "NO" border = "0" framespacing = "0">
<Frame src = "menu.html" id = "leftbar" noresize name = "menu" scrolling = "yes">
<Frame src = "main.html" id = "rightbar" noresize name = "main" scrolling = "yes">
</Frameset>

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.Copy codeThe 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:Copy codeThe Code is as follows: <frame src = "top. php" name = "topFrame" id = "topFrame" scrolling = "no">
<Frameset cols = "180, *" name = "btFrame" id = "btFrame" frameborder = "NO" border = "0" framespacing = "0">
<Frame src = "menu. php" id = "leftbar" noresize name = "menu" scrolling = "yes">
<Frame src = "main. php" id = "rightbar" noresize name = "main" scrolling = "yes">
</Frameset>

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:Copy codeThe 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:Copy codeThe Code is as follows: <frame src = "iframe. php? Src = top "name =" topFrame "id =" topFrame "scrolling =" no ">
<Frameset cols = "180, *" name = "btFrame" id = "btFrame" frameborder = "NO" border = "0" framespacing = "0">
<Frame src = "iframe. php? Src = menu "id =" leftbar "noresize name =" menu "scrolling =" yes ">
<Frame src = "iframe. php? Src = main "id =" rightbar "noresize name =" main "scrolling =" yes ">
</Frameset>

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.