Skip to content

Instantly share code, notes, and snippets.

@iampava
Created March 28, 2018 12:50
Show Gist options
  • Save iampava/6e7d3698f5c15d756bdd429b623c0a38 to your computer and use it in GitHub Desktop.
Save iampava/6e7d3698f5c15d756bdd429b623c0a38 to your computer and use it in GitHub Desktop.
Reusable HTML "components" with PHP
<?php
function createHeader() {
return '
<header>
<h1>
<span class="emoji">πŸš€</span>
TW Checklist
<span class="emoji">πŸš€</span>
</h1>
</header>
';
}
?>
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<?php
include "./header.component.php";
echo createHeader();
?>
</body>
</html>
@juliadmytrenko
Copy link

Cool. That's what I've been looking for

@pokedotdev
Copy link

also works

<?php function createHeader() { ?>
      <header>
          <h1> 
              <span class="emoji">πŸš€</span> 
                  TW Checklist 
              <span class="emoji">πŸš€</span>
          </h1>
      </header>
<? } ?>

@JohnnyWalkerDigital
Copy link

Also works (no PHP):

  <header>
      <h1> 
          <span class="emoji">πŸš€</span> 
              TW Checklist 
          <span class="emoji">πŸš€</span>
      </h1>
  </header>

@Mohammed4mach
Copy link

Also works (no PHP):

  <header>
      <h1> 
          <span class="emoji">πŸš€</span> 
              TW Checklist 
          <span class="emoji">πŸš€</span>
      </h1>
  </header>

Yes but it is better to wrap it in a function, Its importance appears when you need to pass props.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment