Here's the code I have in the html file to "include" the file "vmenu.php"
<div id="apDivVistaMenus">
<?php
include 'vmenu.php';
?>
<!-- Begin Vista-Buttons.com -->
<!-- End Vista-Buttons.com -->
</div>
The menus used to be between the comments below the php include request. But I save that code into the vmenu.php file, which looks like this:
<link href="../menu-files/peaceland_styles_zkkus.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript"> var vbImgPath="../menu-files/"</script>
<script type="text/javascript" src="../menu-files/sczkkus.js"></script>
<noscript>Xp Style Menu by Vista-Buttons.com v2.73</noscript>
What's the problem?
They are both in the same directory.
If I put the code from the vmenu.php back into the html file, it will load fine.
Thank you!
Note that, in order for PHP includes to work, the file must be parsed by the PHP engine. By default, major web servers like Apache do not run .html files through the PHP interpreter, so you must either specify in your web server's configuration that you want to parse .html files as PHP files, or rename the .html file to a .php file.
Change your code to this:
<div id="apDivVistaMenus">
<!-- Begin Vista-Buttons.com -->
<?php include 'vmenu.php'; ?>
<!-- End Vista-Buttons.com -->
</div>
...and you'll be golden.
Related
Im trying to display the contents of the text file with no luck. I have tried php which looked like an easy way to do it with no luck
base.html
{% load i18n static %}
<!DOCTYPE html>
<html>
{% load static %}
<head>
<head lang=en>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
</head>
<body>
<div >
<div class="jumbotron" style="background-color: white; padding: 1.5rem;margin-bottom:i 100.5rem">
<div class="row">
<div class="col-md-3"><img src="{% static 'css/images/hadoop.png' %}"</div>
<div class="col-md-6">
<h2>Impala Query Metrics</h2>
<hr class="my-2" href="{% url 'impala' %}">
</div>
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
$f = fopen("pathtofile/test.txt", "r");
// Read line from the text file and write the contents to the client
echo fgets($f);
fclose($f);
?>
I have also tried
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
readfile("pathtofile/test.txt");
?>
Also:
<?php
include("pathtofile/test.txt");
?>
Im not getting any errors nor seeing any results
There are a few issues here; hopefully this provides some thoughts on where to go.
First, it appears that you want to run PHP code inside an HTML file, as the name of the file is base.html. The PHP interpreter is not configured (by default) to allow this, as it will only run files with the php extension. The fix for this would be to tell your web server to associate html files with the application/x-httpd-php mime type, so html files are ran through the php interpreter.
Second, I noticed the question is tagged with django, which is a Python framework. Do you have a PHP interpreter installed on the server? In order to execute PHP code, you'll need a PHP interpreter, which Python is not. To fix this, you would need to install a PHP interpreter (https://secure.php.net/ - right sidebar)
Third, should you really do this? Python and PHP both serve the same need, to provide server side processing to a web site. I would argue that you should use one or the other, but not both. Since you're already running Django, I would advise that you look for the Python-esque way of accomplishing a file include.
assuming your file is text-file and you want the a html file that your data wrapped inside a div or so then :
I'm not a python fan but for python some links , not exactly same title but may good for beginning:
https://python-forum.io/Thread-read-text-file-using-python-and-display-its-output-to-html-using-django
Django displaying upload file content
https://djangobook.com/generating-non-html-content/
or in php: 0.php
<!DOCTYPE html>
<html>
<body>
<div class="content-wrapper">
<?php
echo file_get_contents( "YOURFILE" ); // get the contents, and echo it out.
?>
</div>
</body>
</html>
So I've recently discovered how to use php includes to include a footer and header in each of my files to avoid copy pasting all the header/footer code to each file. But let's say I have a footer.php, header.php, home.php, and about.php
Do I have my title, opening html/body tag, etc. in the header.php or home.php and about.php.
//header.php
<html>
<head>
links to header.css
links to home.css
links to about.css
</head>
<body>
//home.php
<?php include("header.php"); ?> //PROBLEM: the header.php also includes other .css such as "about.css", etc. that could result in problems later.
</body>
</html>
What Should I do to fix this? One way I thought of is to remove the beginning part(html,head,title) of the header.php file and move it home.css and about.css so they each have their own css links.
You're on the right track. Break out the stylesheets as well as the javascripts into other php files and include them as well. So all pages have the following structure.
home.php
<?php $this_page = "home.php";
include "template.php";
For other pages, just replace the $this_page variable. The structure common to all pages is actually the template.
template.php
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
<!-- CSS-->
<?php include "stylesheets.php" ?>
</head>
<body>
<!-- common header -->
<?php include "header.php" ?>
<section>
<!-- PAGE CONTENT HERE determined by $this_page value -->
<!-- 'content_home.php', 'content_about.php'... have the content-->
<?php include "content_$this_page" ?>
</section>
<!-- common footer -->
<?php include "footer.php" ?>
<!-- link javascript files -->
<?php include "scripts.php" ?>
</body>
</html>
The only thing that changes from one page to the next is the value of $this_page. It's what determines which content gets loaded in the template above, and it also determines which CSS and JS files to include.
stylesheets.php
<?php
$cssDir = "path/to/styles/"; //folder where all CSS files live
//Link each page to its CSS file
$styles = [
'home.php' => 'home.css',
'about.php' => 'about.css',
'contact.php' => 'contact.css',
];
?>
<!-- CSS common to all pages -->
<link rel="stylesheet" type="text/css" href="<?="$cssDir/common.css"?>>
<!-- CSS, specific to the current page -->
<link rel="stylesheet" type="text/css" href="<?="$cssDir/$styles[$this_page]"?>>
The same approach can be used with the javascript you link to in scripts.php. Now that your HTML is into discrete modules, it is easy to edit a part of your site without worrying about another part breaking. In particular I recommend never to open a tag in one php file and close it in another because that would be a nightmare to debug, maintain and modify as your site gets bigger.
About paths:
Remember that when the browser sees the page, in place of include "stylesheets.php" and include "scripts.php", it will see the echoed contents of that file exactly as they are. So in those files you want your path to be either:
absolute paths from your domain root (simplest)
relative paths from the location of the top-level php file (eg home.php)
just the file name, if it is located in PHP's include PATH (places where PHP looks for content by default before throwing an error)
For header and nav you have to create a seperate file like nav.php which will contain only the nav and your site header not <head></head> and include it after your header.php. LIKE
//Home.php
<?php
include("header.php"); this will contain your head part mostly your .css and .js files
include("nav.php"); This will only contain header and nav
// home.php code goes here
?>
Also use below code will automatically get path to your root.
<?php
$PATH = "http://localhost/Folder/"; // change this when needed
$PAGE = basename($_SERVER['PHP_SELF']);
?>
Then Add your files like this
<link rel="stylesheet" href="<?php echo $PATH; ?>assets/plugins/font-awesome/css/font-awesome.css">
the bottom line is your code being accessible & easy to maintain, I would have a head.php, header.php & footer.php file. In the head.php you may want to include your config.php if you are connecting to a database & also have all the <html><head><title><link><script> tags you will include in every page then on your index.php or home.php
include('head.php');
include('header.php');
etc etc
This question already has answers here:
Include another HTML file in a HTML file
(41 answers)
Closed 7 years ago.
is there an HTML non-php way of calling to a file? For example, I am working on a large site that I don't want to have to edit each page when I want to edit the menu, footer, etc. Sort of like how wordpress uses php to include the header/menu data, I'd like to have one file to edit, but without using php. I don't know how possible this is. I am developing the site with HTML5/Bootstrap/JS and would like to avoid php if possible!
One method you can use is the .shtml file extension.
It also has SSI capabilities and is server-side, not client-side, therefore it runs off the server.
Server Side Includes (SSI)
Basic syntax to include files is:
<!--#include virtual="/footer.html" -->
<!--#include file="footer.html" -->
<!--#include virtual="/cgi-bin/counter.pl" -->
You can also include other files inside included files.
For example, say you have a header file <!--#include virtual="/header.shtml" --> and you want to include a navigation bar, you just do
header.shtml would contain
<!--#include virtual="/nav.shtml" -->
all inside the same file, say you call it index.shtml
index.shtml would contain this structure
<!doctype html>
<head>
<!--#include virtual="/js_files.shtml" -->
<!--#include virtual="/metatags.shtml" -->
<title>
<!--#include virtual="/title.shtml" -->
</title>
</head>
<body>
<!--#include virtual="/header.shtml" -->
<div>Hello world!</div>
<!--#include virtual="/footer.shtml" -->
</body>
</html>
and inside <!--#include virtual="/header.shtml" -->
you could have this tag included in there <!--#include virtual="/nav.shtml" -->
containing
Home -
About -
Info
By using the same or similar structure for all your files, any change you make to one (include) file, will be affected globally throughout the site.
This is a method I use myself for certain websites where PHP isn't a requirement and have used for many years and works quite well, including Bootstrap-based.
References:
http://httpd.apache.org/docs/2.2/howto/ssi.html
http://en.wikipedia.org/wiki/Server_Side_Includes
http://www.htmlgoodies.com/beyond/webmaster/article.php/3473341
If your are already using java script lets just use JQuery
Using jQuery:
index.html:
<html>
<head>
<script src="jquery.js"></script>
<script>
$(function(){
$("#header").load("header.html");
$("#footer").load("footer.html");
});
</script>
</head>
<body>
<div id="header"></div>
<div id="footer"></div>
</body>
</html>
header.html
<p><b> This is my header file </b></p>
footer.html
<p><b> This is my footer file!</b></p>
You can use an iframe to include one HTML page inside another page.
I am building my site using HTML files. I would like my header and footer to be dynamic so that I can easily update anything... verses updating 10+ files every time. I'm not familiar with creating a .php file for this use.
I've researched and tried a few ways to do this... but it's not working...I know I'm doing this wrong. haha...
I do not want to make my index.html into index.php. Is there an easier way to do this?
If you absolutely can't make your index a php file. Then, you can always make an ajax request to get the header and footer. However, it is very simple to have a dynamic header and footer with php.
The index
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php include 'header.html'; ?>
<?php include 'footer.html'; ?>
</body>
</html>
The header.html file
<header>
<p>Some stuff in my header...</p>
</header>
The footer.html file
<footer>
<p>Some stuff in your footer</p>
</footer>
The style.css file
header {
/* My styles here */
}
footer {
/* My styles here */
}
Hope this helps you.
You can use javascript to load the header and footer. Create a header.html and footer.html and load them via AJAX.
You can use Server Side Includes and save your files as .shtml
More information from Wikipedia: http://en.wikipedia.org/wiki/Server_Side_Includes
The syntax is eg. <!--#include file="header.shtml" -->
Edit your .htaccess file and add these line, this will tell apache to treat .html as .php
AddType application/x-httpd-php .html
and for .htm
AddType application/x-httpd-php .htm
<html>
<body>
<!--#include virtual="head.html" -->
<h1>Body goes here...</h1>
<!--#include virtual="footer.html" -->
</body>
</html>
you could try something like this.
If it doesn't seem to work, try changing your extension to .shtml, instead of .html.
for more info on server include you can try this site: http://www.boutell.com/newfaq/creating/include.html
I intent to create a template PHP file, this template will only serve the design, not the content. The purpose is to decrease the development time in a sense that when creating a new PHP file or new module, I can only need to concentrate on the main function of that PHP file not the design. Once I created the new file using the template, it should be able to display the consistent design and serve its specific function.
The issue is that I am not sure on how to make the design of the template works and applied to all of the new files created regardless of the location (as long as it is within the root directory).
As an example:
root directory (www.example.com): /
homepage (www.example.com/index.php): /index.php
css file: /style/style.css
template file: /template.php
newly created file (www.example.com/subone/find/css/file.php): /subone/find/css/file.php
another newly created file (www.example.com/subtwo/locate/css.php): /subtwo/locate/css.php
Content of the homepage (which is created base on the template.php, but the CSS file location is hard coded):
<html>
<head>
<title>Testing</title>
<link rel="stylesheet" type="text/css" href="style/style.css" />
</head>
<body>
<div id="header">logo and login form goes here
<div class="nav"> navigation goes here;</div>
</div>
<div id="main">main content goes here;</div>
<div id="footer">footer goes here; </div>
</body>
</html>
but, when I created a new file, /subone/find/css/file.php
the location of the css must be changed and specified manually, like this:
<html>
<head>
<title>Testing</title>
<link rel="stylesheet" type="text/css" href="../../../style/style.css" />
</head>
<body>
<div id="header">logo and login form goes here
<div class="nav"> navigation goes here</div>
</div>
<div id="main">main content goes here;</div>
<div id="footer">footer goes here;</div>
</body>
</html>
So, what I want to achieve is that, when creating a new file (/subone/find/css/file.php), I don't need to do anything, I can straight away concentrate on the main section:
<html>
<head>
<title>Testing</title>
...style.css is handled automatically
</head>
<body>
<div id="header">logo and login form goes here
<div class="nav"> navigation goes here</div>
</div>
<div id="main">main content goes here;
<?php
//I can continue to edit the file from this line onward
echo "I am concentrating on the main function of file.php right now!!";
?>
</div>
<div id="footer">footer goes here;</div>
</body>
</html>
example page can be seen at (only the desired design): neoborn.kodingen.com
I accept any answers as long as it can achieve my intention (template).
Thank you :)
Why don't you use absolute paths when referring to CSS files and other resources in your template file?
For example:
<link rel="stylesheet" type="text/css" href="/style/style.css" />
There are 2 options,
Use absolute paths for your css files <link rel=stylesheet href="/style/style.css">
Use HTML's <base> element to cause all relative paths on the page relate to it.
I would use a easy to install template engine. That will help speed up development and still give you the freedom to do whatever PHP you like.
Try http://www.raintpl.com/ that should be quick and easy for you to install and get back to coding the pages. If you include it in your PHP inc folder, it will be available for every PHP file you create. So you won't need to add an include line at the top of each PHP file.
Index.php
<?php define('BASE_URL', 'http://localhost'); ?>
Template.php
<link rel="stylsheet" type="text/css" href="<?php echo BASE_URL; ?>/style/style.css ?>" />