Is there a Master Page in PHP?

Asked

Viewed 97 times

0

It is a recurring question that I have in relation to PHP, I am new in PHP programming and I am developing a project of this, I did it as follows, it works but I would like a more practical way in relation to this. I created a file header.php with only the Header of the page and a footer.php with only the Footer. Below the code:

<?php require('header.php') ?>

*//content here*

<?php require('footer.php') ?>

Is there a framework, plugin or something like this to make it easier to use Master Page in PHP? Thanks in advance!

1 answer

1


You can use a template engine to do this, Smarty is one of the most popular. With it, you create template pages with the extension. tpl, and within these pages, you place the HTML and markup codes, which will be replaced by your PHP page. For simple example, you could have a template with this content:

Mensagem: {$msg}

To customize the message, you would do this on your PHP page:

<!--?php
include "smarty/libs/Smarty.class.php";
$smarty = new Smarty();
$smarty--->template_dir = "smarty/templates";
$smarty->compile_dir = "smarty/templates_c";
$smarty->config_dir = "smarty/configs";
$smarty->assign("msg", "Hello World!");
$smarty->display("meu_arquivo_de_template.tpl");
?>

Here is the documentation:

https://www.smarty.net/docsv2/pt_BR/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.