I need to include a html file inside a php file, I tried using include and require in php file, but css styles are not applied and only the content is included. Is there a way to include the full html file with styles and jquery?
3 Answers
There's no such thing as a PHP script. There's just files that happen to contain PHP code blocks. You can include() anything you want, but unless that included file has a <?php ... ?> block in it somewhere, the file's contents will simply be treated as output.
If css isn't being applied, then make sure that that your style sheets are actually being loaded, and that the HTML is being included in the proper place in your page's DOM.
4 Comments
absolute path. e.g. <!--#include virtual="/path/to/file.html" -->. Also, if I may suggest; if you're going to use the .shtml equivalent, include another .shtml file, that way you will be able to include more later on, should you choose to do so../ in front of your filename. e.g. <!--#include virtual="./file.html" --> which could be problemsome. You can also use <!--#include file="./file.html" -->, but that directive calls for ALL files to reside inside the SAME folder.View the source of the page and see the path of the CSS file it's showing. The path needs to be either absolute or relative to the PHP file's path. Example:
File structure:
./index.php
./html/myfile.html
./html/css/style.css
myfile.html includes "css/style.css"
index.php includes html/myfile.html
Now, myfile.html may look alright when you open it directly, but the style won't be applied when you include it in your PHP file. Here's why:
If you view the source of index.php (open in browser and view the DOM) you'll see that it's trying to load css/style.css but that file doesn't exist. Instead, it should be html/css/style.css so you would have to edit your HTML file to reflect that.
include-ing, it should be fine :o