Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

294
Views
HTML: ¿Cómo duplicar el pie de página en todas las páginas sin PHP?

Buscando asesoramiento sobre si es posible tener un footer.html y duplicarlo en todas las páginas sin usar PHP.

Sé que puedo usar include("footer.php"), pero ahora todas mis páginas están en HTML y tendré que cambiar todas las rutas CSS.

Leí w3school sobre cómo usar w3-include-html y javascript. Sin embargo, me doy cuenta de que el javascript se está retrasando en cada página, lo que hace que la carga de la página sea más larga.

¿Hay alguna otra opción?

 <body> <script> function includeHTML() { var z, i, elmnt, file, xhttp; /* Loop through a collection of all HTML elements: */ z = document.getElementsByTagName("*"); for (i = 0; i < z.length; i++) { elmnt = z[i]; /*search for elements with a certain atrribute:*/ file = elmnt.getAttribute("w3-include-html"); if (file) { /* Make an HTTP request using the attribute value as the file name: */ xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { if (this.status == 200) {elmnt.innerHTML = this.responseText;} if (this.status == 404) {elmnt.innerHTML = "Page not found.";} /* Remove the attribute, and call this function once more: */ elmnt.removeAttribute("w3-include-html"); includeHTML(); } } xhttp.open("GET", file, true); xhttp.send(); /* Exit the function: */ return; } } } </script> <div w3-include-html="footer.html"></div> <script> includeHTML(); </script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Podrías pensar diferente, pero no sé si es lo que quieres, porque la arquitectura de tu aplicación crecerá/se volverá un poco fea.

Usted define un script php, que está cargando su html estático y agrega el código php que desea. Entonces necesita una regla de reescritura para que el script sea el centro de su pequeño universo html ;-)

Un ejemplo, que debería funcionar en un apache con rewrite-mod habilitado.

Mencione que crea esta estructura de directorio en su servidor:

  • .../.htaccess
  • .../index.php <<< esto representa el "encabezado", el contenido de sus archivos html y el último pie de página
  • .../html-pages <<< coloque sus archivos aquí

Coloque un .htaccess en la carpeta raíz:

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond "%{REQUEST_URI}" !^.*/index\.php$ RewriteRule ^(?!.*index\.php)(.*)$ /index.php/$1 [QSA,L]

Coloque un index.php en la misma carpeta:

 <?php ... here could be your header-code define ('PAGES_DIR', __DIR__ . '/html-pages') define ('DEFAULT_PAGE', 'index.html') // we need to handle virtual pathes $requestPath = false; if (isset($_SERVER['PATH_INFO'])) { $requestPath = $_SERVER['PATH_INFO']; } elseif (isset($_SERVER['ORIG_PATH_INFO']) && strpos($_SERVER['ORIG_PATH_INFO'], basename(__FILE__)) === FALSE) { $requestPath = $_SERVER['ORIG_PATH_INFO']; } if ($requestPath == '/' || strlen(trim($requestPath)) == 0 || strlen(trim($requestPath)) == basename(__FILE__)) { $requestPath = DEFAULT_PAGE; } // this sends the content of your file to the browser @readfile(PAGES_DIR . "/$requestPath"); ... now your footer-code

Y sus archivos html deben colocarse en la carpeta "páginas html".

Si lo ha hecho, su servidor debe manejar http://domain.tld/bla-fasel-blub.html de la siguiente manera:

  1. redirigir la ruta no existente a index.php
    Regla de reescritura ^(?!. index.php)(. )$ /index.php/$1 [QSA,L]
  2. representar el encabezado
  3. lea el archivo html solicitado (el $1 de RewriteRule será "bla-fasel-blub.html" y se convierte en el valor de "$requestPath") y envíe el contenido al navegador
  4. renderiza el resto de index.php (el pie de página o lo que sea)

Espero que te sirva, generando una idea para tu problema.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!