Forum
Outputting HTML in App is causing "Cannot modify header information" errors
Hi,
I've built a small Perch app to skin the admin, which outputs CSS and some other things in the head using the Perch app API.
It works great but I have a problem when trying to echo out admin favicon, getting a "Cannot modify header information"… error. I know this error is usually caused by things outputting in the wrong place. I assume it's because I'm just echo'ing it out rather than using an official API method.
$Perch = Perch::fetch();
$Perch->add_css($API->app_path() . '/standard-admin.css');
echo '<link rel="shortcut icon" href="/perch/addons/plugins/ui/favicon.ico">'; <-- This causes an error
How would I echo this out correctly?
I did try looking through the API documentation but couldn't piece anything together—either that or I'm not looking correctly.
Incidentally, although I was told about $Perch->add_css
through the forum, I could not find this documented and I'm curious where I would find this info. I'd like to be able to troubleshoot this on my own but either it's not documented or I can't find it.
You want to use
$Perch->add_head_content()
for that.The whole point of using the API here rather than just blindly echoing is that the insertion point is managed.
Thanks, that worked.
Is that documented by the way? I cannot find it in the docs—https://docs.grabaperch.com/search/?q=add_head_content
No, it's not.