pull site structure through database

Asked

Viewed 116 times

0

I have a doubt I have a relatively large site where a section of the site repeats often to where the structure and equal on all pages what changes is the content that is pulled by the database most wanted to know if I can put the php hmlt structure inside the database because if I want for example by a dív or whatever other element i vo te that edit page by page then it would be better to create the page and pull its HTML structure by the database there so all the others would change too

  • I would recommend using a framework like vuejs, Aravel...

2 answers

3


In particular I prefer to create a master page with the html structure and give a include on the other pages.


<--Estrutura da pagina mestre-->

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <!-- Imprime o titulo da pagina filho -->
    <title>Página Mestre | <?php echo $titulo; ?></title>
</head>
<body>
    <!-- Menu -->
    <nav></nav>

    <!-- Conteudo da pgina filho -->
    <?php echo $conteudo; ?>

    <!-- Roda Pé -->
    <footer></footer>
</body>


<-- Página filho -->

<?php ob_start(); ?>

<!-- Conteudo da pagina filho vai aqui -->

<?php
$conteudo = ob_get_contents();
ob_end_clean();
// Titulo da pagina filho
$titulo = 'Home';
// Include da página mestre
include_once 'pagina_mestre.phtml';
  • Thanks for the help I hadn’t thought to make in this very good way

  • You could help me because the content does not appear

  • I believe you have to run the child page instead of the master page in this case, because the child page is including the master page (include_once 'pagina_mestre.phtml';).

  • Yes you should call the son page and not the master page. And detail you can have more than one child page for example Home, Services, Projects, Contact and etc including the master page.

1

It is not necessary to use database, just use include or include_once, which aims in php to "bring the text of another file" to the page where include was used. Then you can take those files that repeat themselves and include them on the other pages, and when you want to edit just edit this separate file.

  • Yes thanks for the help

Browser other questions tagged

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