I got 2 files. File B is gtting called in File A. Now i need to edit some things in File B for which i need variables from file A.
I now tried to include File A (parent file) to file B like this:
(I am using SMARTY for my page, basically it´s the sam like a normal PHP include)
{include file='file:/standard-usermod.html'}
Now when the file gets included i can indeed use the variables of File A but the layout is a mess. It also includes me Layout things of file A, but i only need it´s variables. Is there a posibility with PHP (it does not have to be written in SMARTY) to include a file just for using the variables without showing it´s layout on the page?
Use ob_clean() after file include
Related
I'm new at the scene and I'm using Bootstrap 3 and this template for the first time. I need help with the navbar. In the template each content.html has their own navbar.
I need the navbar in a separate file, because I do not want to make changes in every single content.html file.
In my old site without Bootstrap I worked with:
<?php
include("includes/navigation.html");
Can someone help me?
You need configure to put your repeated html data's in a single file and include that one into another.
Lets simple,
if your Project structure like this
project(folder)
db(folder)
Dbconnection.php(file)
js(folder)
jquery.js(file)
css(folder)
bootstrap.css(file)
index.php(file)
page1.php(file)
page2.php(file)
Create a new file with contents of your navbar html tags alone.
For ex. in your nav-menu.php contains
<navbar>
......
......
</navbar>
and save them into new includes folder in your project. So now your project structure will be like this one,
project(folder)
db(folder)
Dbconnection.php(file)
js(folder)
jquery.js(file)
css(folder)
bootstrap.css(file)
includes(folder)
nav-menu.php(file)
index.php(file)
page1.php(file)
page2.php(file)
Now you should include this file(nav-menu.php) in all the template files using php include method, like
include("includes/nav-menu.php");
Add this above code in all of your common files.
You can use
<?php include("includes/navigation.php") ?>
in this project too.
Fastest way that comes to my mind is to just include the code you need to change for every page in a separate switch/case and call the different cases at the top of the page that is including the navbar.
Just note your navigation file needs to be .php, not .html like your example.
I'm learning php, been trying to make a cms, but when I use an include for the header this results in the page appearing as if it were written in pre tags. There's no errors when I debug or anything. And I'm completely stumped. When I put the header back in without the include it renders just fine.
<?php include("..\includes\layouts\header.php"); ?>
That's the include I'm using.
I've tried using the full path name, tried it in different browsers and using :
include($_SERVER["DOCUMENT_ROOT"]
Check that you are closing your php tags, ending your strings with semi colons etc.. My guess is that your html is being sucked into the php code which freaks out and just dumps it.
Maybe try one of the validators such as http://phpcodechecker.com (I have not used this one so I cannot comment on it's effectiveness)
Edit: I am rereading your post and I think I understand what you are trying to say - your header contains the path to your css and when you put it in a separate php file the css doesn't work? So the first thing to do is determine if the issue with the php path or the css path inside the header.php file. Look at your source code to see if the header code is being included - if it is then play around with the css path - though including the header in a php file will not cause that css path to change.
I am guessing that your header is not included at all from your mention of paths. include() works from the loading file's location. The path it wants is a server path and not a url. The one that you have above: ../includes... means that you have an include folder at the same level as the loading file such as (assume index.php is the main file):
/includes/layouts/header.php
/somedirectory/index.php
The ../ means - drop down one directory then go up from there.
If your path is more like:
/includes/layouts/header.php
/index.php
Then the include would be:
include('./includes/layouts/header.php');
Let me know if that works - if it doesn't try to explain your directory structure.
I have a php page(index.php) that includes another html file(footer.html). Am using dreamweaver, and my problem is: The included file(footer.html) shows in the main file (index.php) in dreamweaver design view, but does not show in the browser preview. I have both the php files in the root directory, so they're at the same level. I have tried using require rather than include with the same result. My include code is:
<?php include("footer.html");?>
does anyone see something wrong off the bat?
Do realy exist file "footer.html"?
If no create them.
Is file "footer.html" in the same directory as "index.php"?
If no add it to the same directory.
Do you have any content in your "footer.html" file?
If no add any and check if it appears on page.
I downloaded a Template + CSS File for a Website that I'm Building, the template worked well until I tried to break it down and put every code in its own file (for easy modification and editing in the future).
So, when I cut the head part which included (Title + Meta Data .. etc ), and put it in its own file, and replaced it (for sure) with an include() function, I lost the CSS styles and returned to the basic & standard style (Black & white with no extra format .. etc)
Where did I Go wrong? Knowing that here is the include function that I've used:
<?php
include 'files/head.php';
?>
With an URL like file:///C:/xampp/htdocs/test6/index.php PHP is NOT executed. You must run it with apache being involved. Currently you are opening your PHP script as a regular txt or html file - it is just passed to browser without processing.
In order to make include function work you must run it with apache. As you are using xamp, I think you should simply open it with URL like http://localhost/test6/index.php In this case, apache will get that request and pass it to PHP. PHP engine will interpret your PHP script and "replace" include files/head.php with a content of head.php.
If everything is Ok, after pressing Ctrl+U (or looking at HTML with Developer Tools or Firebug) you should see a content of head.php instead of <?php include ....
Please note that css files should be linked with relative URL like css/screen.css. Or absolute URL like http://localhost/test6/css/screen.css. like Search for relative and absolute URLs in google for more info.
Specifically in theme php files, such as say index.php. The very first thing in most theme's index.php file is a call to get_header() which is most certainly not not defined in index.php, so how does it know about that function?
I'm not very familiar with php, but from what I've read just now there is an include and require keyword which work more or less the same way as an import in Java or include in C, which I understand and makes sense. However, the only usage of these keywords in this particular index.php file includes a file that doesn't contain a definition of get_header(), nor does it have any includes or requires of its own (though it does call some more functions it has no right to know about, much like index) so clearly that's now how it knows about this function.
Anyway, I was just hoping to remove some of the 'magic' from wordpress for myself. Thanks in advance!
The index.php in each theme isn't ever called directly, rather those are included by other files in Wordpress.
get_header is actually defined in wp-includes/general-template.php.
The templates files are loaded by require_once function calls in the load_template function of wp-includes/theme.php
Themes' index.php file is not the main file that's processed, that one resides in the root directory of your wordpress installation. It calls several files setting up the environment and then loads the template. You might want to look in the wp-content/plugins directory, maybe starting with the globals.php file to tweak some of the magic.
Also the wp-includes directory contains interesting files, the get_header() function is defined in general-template.php in that directory.
Specifically in theme php files, such as say index.php. The very first thing in most theme's index.php file is a call to get_header() which is most certainly not not defined in index.php, so how does it know about that function?
A theme's index.php file is never executed on its own. All requests to a WordPress install go through the main WordPress index.php file.
Most likely, index.php is being included in another file and that file either defines the get_header() function or - more likely - contains yet another included php file which in turns defines the get_header() function.
You have to understand that the php include and require functions behave like an in-line include. It simply treats the include file as being part of the original script.. a big concatenated script (so not really like an import in Java)
You may want to start at the .htaccess file which will tell you which .php file is assigned to handle the request. Based on what you said in your question, it will probably not be index.php. When you find the top-most php script, you can work your way from there with the includes and requires..
in c and in java you declare the import at the top of you files. In php you can set the includes almost anyware you want.
so this is valid:
<?php
// define some functions
?>
<html>
<head>
<?php
include('head.php');
?>
</head>
<body></body></html>
it is possible that these get_header() methods are declared somewhere before the index.php page is included.
If you want to leave out the <?php get_header(); ?> then there will be no problem