LeonLatex Posted July 1, 2022 Share Posted July 1, 2022 I am about to set up a test site. When it comes to the HTML tags, where do you split each HTML file by it's tag's that you want to include in the index.php I know there is no standard about this, so it's up to each other how to do it. Like i am split it up in 3 files; header.php , main.php and footer.php. main is used for the sites content. In header.php i got: <!doctype html> <html lang='no' translate="yes"> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> In main.php with the content i got: <body><?php .................content................ ?> etc And in footer.php i got: </body> </html> With this setup, I have never experienced any problems, but since you have a better understanding and are more experienced than me can tell me another way you are doing it, and why you do it that/your way? Quote Link to comment https://forums.phpfreaks.com/topic/314988-include-header-main-footer/ Share on other sites More sharing options...
requinix Posted July 1, 2022 Share Posted July 1, 2022 The header/content/footer style is at least 10 years out of date. Templating is better. Approaches vary, but the point is that you have a single file containing the entire template for the page, and you insert content in the places it needs to go. <!doctype html> <html> <head> <title><?= $title ?></title> etc. </head> <body> <?= $body ?> </body> </html> If you don't want to render your output to strings, things like $title and $body can instead be functions that are called and output what they want directly. Quote Link to comment https://forums.phpfreaks.com/topic/314988-include-header-main-footer/#findComment-1597843 Share on other sites More sharing options...
LeonLatex Posted July 1, 2022 Author Share Posted July 1, 2022 21 minutes ago, requinix said: The header/content/footer style is at least 10 years out of date. Templating is better. Approaches vary, but the point is that you have a single file containing the entire template for the page, and you insert content in the places it needs to go. <!doctype html> <html> <head> <title><?= $title ?></title> etc. </head> <body> <?= $body ?> </body> </html> If you don't want to render your output to strings, things like $title and $body can instead be functions that are called and output what they want directly. I see. But I am an old man 😛 But at least I am using variables like $title But requinix, can you please tell me about this: <?= $body ?> Why have you replaced php with = after <? and then calling the body variable ? Quote Link to comment https://forums.phpfreaks.com/topic/314988-include-header-main-footer/#findComment-1597844 Share on other sites More sharing options...
requinix Posted July 2, 2022 Share Posted July 2, 2022 1 hour ago, LeonLatex said: But requinix, can you please tell me about this: <?= $body ?> Why have you replaced php with = after <? and then calling the body variable ? I take it you're not familiar with that syntax?https://www.php.net/manual/en/function.echo.php Quote Link to comment https://forums.phpfreaks.com/topic/314988-include-header-main-footer/#findComment-1597846 Share on other sites More sharing options...
LeonLatex Posted July 2, 2022 Author Share Posted July 2, 2022 30 minutes ago, requinix said: I take it you're not familiar with that syntax?https://www.php.net/manual/en/function.echo.php No, I am not. I will read about it on PHP net. Thanks for the link 🙂 Quote Link to comment https://forums.phpfreaks.com/topic/314988-include-header-main-footer/#findComment-1597848 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.