We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Error, Api

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.

Jay George

Jay George 2 points

  • 1 year ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

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

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, it's not.