0

A few days ago I started with web development and the idea is to write a guestbook with a login. A user with a valid user account can login/logout, create new entries and edit his own entries. He can also change his own password and create new user.

The base site (header, footer, navigation, div's etc) is always the same, but the content is different/dynamic: Displays the existing articles, create articles, create user etc.

So my problem is: How can I reuse the HTML code ?

  • First way: Include header and footer as includes in every PHP page and print the page results via echo. This has a disadvantage: Using jQuery is difficult (Because jQuery is clientside and output it in PHP gets messy).
  • Second way: Every page contains the complete HTML page and makes an jQuery-Ajax call - One change in the design results in changing every file. Also I have to create a PHP file for each request.

Are there any other methods I don't know ?

swaechter
  • 1,357
  • 3
  • 22
  • 46

3 Answers3

1

I think that the best practice in your case is using template engine, like Twig or Smarty. It will allows you to generate arbitraty content on server-side and output to html.

Andrey Chul
  • 136
  • 11
0

You can make your own HTML master page of that include header, footer, and those content that are reusable in your page. This link may help you link

Hisham
  • 455
  • 4
  • 16
0

If you are just getting started and interested in learning how to build and manage an interactive website, I would suggest you start with one of the existing Content Management Systems (CMS) like Wordpress, Drupal, or Joomla.

It is quite likely that you will find all the functionality you need for your purposes in these products out of the box, and because they are open source, you can begin to study these platforms to learn about how to customize them and make them do what you want.

Start with following a tutorial on how to build your own plugin for Wordpress, and think about extending existing products rather than building your own from scratch. I believe that you can learn the same amount or more by following this approach, and you should be able to accomplish more as well.

By the way, I strongly recommend Wordpress above any other CMS for almost any project.

Brandon Johnson
  • 329
  • 5
  • 11
  • Thanks for your reply. Sadly I cannot use frameworks with this size/complexity. In the meantime I use Mustache as a template library and a request controller for incoming requests. This works great – swaechter Jan 27 '14 at 13:28