How to solve the unified header, referencing different CSS issues?

Source: Internet
Author: User
Tags zend framework
When you make a Web page, you always make the header part a unified one and then introduce it on a different page. However, different pages may have their own different styles, different JS, of course, there are different and other information. <br/> These original parts of the general, because these are different, how do we solve them? <br/> I can think of the two solutions <br/>+ in the header to make a judgment <br/>+ the header in the thin, only to do a common part of the rest, or let each page, write themselves. </p> </p> <p> Reply Content:</p> <p> Site page, will always make the header part of a unified, and then on different pages cited Into. However, different pages may have their own different styles, different JS, of course, there are different <title> and other information. <br/> These original parts of the general, because these are different, how do we solve them? <br/> I can think of the two solutions <br/>+ in the header to make a judgment <br/>+ the header in the thin, only to do a common part of the rest, or let each page, write themselves. </p> <p class= "Answer fmt" data-id= "10200000003543 "> <p> in the page that needs to refer to the header: </p><pre class=" Brush:php;toolbar:false "&GT;&L T;code class= "lang-php" ><?php$page_titLe = ' default page name '; $page _css = '; $page _script = '; require_once (' header.php ');? ></code></pre><p>header.php:</p><pre class= "Brush:php;toolbar:false" ><code class= "lang-php" ><peader> <title><?= $page _title?>

I feel this problem is the importance of the existence of templates. In general is often the display of the title article name (variable) and the site title (variable) This, so it if is more convenient to judge, a variety of blog topics (I contact this more to say this) also basically do this, similar to:

<?php if(isset($post['title'])) echo $post['title'].' - '; ?><?php echo $sitename; ?>

As for the CSS is generally basically the page changes are not small, in this case, you can try to use the condition to determine the different pages to add some of the difference id or class attributes, while in the style.css file description of the modified content, similar to the following:

">

Of course you can also consider adding different styles of code to the non-common parts, as you might say in the second method. If the style of the page is too large, it is recommended to re-use a template page (for example head.index.html and head.page.html the like), because the template itself is the layout of the same style of the template, if it is two different pages referenced by the same template file, You're going to get dizzy in the back, aren't you?

This question can be answered simply by referring to the implementation of the layout of the Zend Framework, which is simply:

1, the header such things templated;
2, the final page by assembling generation;
3. Use a variety of helper to control the content of the parts that need to be parameterized.

Many PHP frameworks have similar components, to choose a reference to the specific implementation of it.

Saejs seems to have been born for this kind of problem, right?

In the controller layer, the file name of the CSS is assigned to the template in the form of an array, and the header file loads the CSS through foreach

Template templates with templates

Template engine layout you have it straight.

  • 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.