0

I am building my own template system. I am asking myself what is the best/fastest way to Output templated html. Example: body.php

Method1: Building a echostring

$layout = '
<body>
<div id="header">

        '.$header.'
</div>
</body>';

Method2: Html with encapsulated php areas

<body>
<div id="header">

      <?php  echo $header; ?>

</div>
</body>

What is your recommendation and why?

bergman
  • 185
  • 4
  • 13
  • 2
    [Horses for courses](http://www.usingenglish.com/reference/idioms/horses+for+courses.html). – eggyal Jul 11 '13 at 18:25

3 Answers3

1

This is more like opinion based. Both ways work but I personally find the 2nd way to be easier to spot errors.

Hristo Valkanov
  • 1,689
  • 22
  • 33
1

I would say Method 2 because its a bit easier to manage and see your code this way.

One of the biggest problems i have dealt with is trying to decipher html when its in a string, typically your editor will not color code html within a string so it becomes hard to see and make changes to HTML.

If your lazy and dont want your own templating system, Codeigniter is pretty awesome and has a lot of resources to help.

http://ellislab.com/codeigniter/

Hopefully that helps!

Goku Nymbus
  • 571
  • 2
  • 11
0

A lot of people will opt for separation of languages, but as others stated, this is more opinion based. This question was asked before also if you're looking for more views on the situation.

Community
  • 1
  • 1
Mattiavelli
  • 888
  • 2
  • 9
  • 22