Reputation: 542
I have a codeigniter project (but I'm not sure if it's a codeigniter issue or php in general).
In my template file I write some HTML with php in it.
<?php $title = "some value" ?>
<!DOCTYPE html>
<head>
<title><?php echo $title; ?></title>
...
</head>
<body>
...
There is some php logic before the doctype that calculates some variables being used in the head section. This all works fine up until now.
As soon as I now add some more php logic, the entire head section is printed in the body tag instead of the head where it's supposed to print.
Also, I don't use echo or any variant in my newly added php logic, however some variables are just being printed at random (at the start of the body tag).
So things that go wrong:
Upvotes: 0
Views: 1293
Reputation: 1
I saw some strange behavior on Code Igniter, like html tags in wrong place and the showing of strange double quotes after the tag.
I solved when I noticed my wrong double loading of same file of constants configuration:
$this->config->load('italia', TRUE);
$this->data['italia'] = $this->config->item('italia');
After deleting second load, all problems disappear...
Upvotes: 0
Reputation: 5426
Are you rendering a view within the body? Make sure that view doesn't use a layout, if it does it would render the head again within the body.
Upvotes: 0
Reputation: 15609
It's because of 'un finished' PHP. You're not closing your first line with ;
.
Make sure you finish all your php lines with a ;
when necessary.
For example:
<?php $title = "some value"; ?>
^ make sure you have this
Also, as it's codeigniter, try setting these types of variables in the controller
.
For example:
controller:
$data['title'] = "Some Value";
$this->load->view('index', $data);
Then you can just use
<title><?php echo $title; ?>
in the view.
Upvotes: 3