Inlining CSS using content representations and external composer library

Hi!

I want to use this composer tool to move my CSS styles inline.

I tested this by creating a new template with filename inlined.php and passing the html to a variable using file_get_contents.

It worked if I used a static url from a remote file, but not with localhost. So that’s one issue I’d like to resolve.

I also want to use a content representation to render an inlined version of a page, and pass the html dynamically using $page->url.

So I have a new template file called email.inlined.php, with this content:

<?php 

use Pelago\Emogrifier\CssInliner;

$html = file_get_contents($page->url());

$visualHtml = CssInliner::fromHtml($html)->inlineCss()->render();
	
echo $visualHtml;
	
?>

but I get the following error in the debugger:

file_get_contents(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0

Is this something I can fix in the Kirby config file, or will it require me to change something in my web hosting settings somehow?

You would have to change this in your php.ini, not in the Kirby config file.

Thank you

Are there any security concerns around doing that? My server experience is very minimal.

Never mind, I’ve been in touch with my hosting provider about this.

And yes, it appears to be a security weak spot to enable allow_url_fopen.