How do you include multiple page content in one php include file?

后端 未结 1 1898
离开以前
离开以前 2021-01-24 08:30

I am wondering how would I include various elements (header, footer, nav), in one php file to be included on various pages, rather than creating multiple php files to be called

1条回答
  •  故里飘歌
    2021-01-24 09:16

    It sounds like you are trying to avoid templates. The basic idea is to define a separate file for each of head, footer, nav and include those from your content template.

    head.php

      ... 
    

    nav.php

      page1   page2   page3 
    

    foot.php

     
    

    And to create a complete page, you would do:

    
    

    Now, if I understand correctly, you want to include only one file and be able to generate the various elements (head, nav, whathaveyou). You could do this by wrapping the include statements in functions:

    ubertemplate

    
        An article about prune juice.  foobar  moo 
    " } function() { include 'foot.php'; } ?>

    ..then in your final page, call these functions:

    uberpage

        
    
    
    
    
                                     
                  
提交回复
热议问题