Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/314988-include-header-main-footer/
Share on other sites

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.

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 ?

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.