R
R
retyui2015-11-24 15:50:08
PHP
retyui, 2015-11-24 15:50:08

Inline css embedding files in html, snippet for modx?

Need to implement opening css file and embed its content in html

<head>
    <style>[[inline? &file=`assets/css/critical.css`]]</style>
    ...

The whole problem I have is to build the path to this file (

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
R
retyui, 2015-12-11
@retyui

Embeds files in code

<?php
$assetsPath = $modx->getOption('assets_path');

$file = !empty($file) ? $file : $modx->getOption('file', $scriptProperties, '');

$myfile = fopen($assetsPath . $file, "r");

if (!$myfile){ return "";}
$inlneCSS = "";

while(!feof($myfile)) {
  $inlneCSS .= fgets($myfile);
}

fclose($myfile);

return $inlneCSS;

Call example:
<script>[[inline?&file=`js/modernizer.js`]]</script>
<style>[[inline?&file=`css/critical.css`]]</style>

S
seriogja, 2015-12-11
@seriogja

Good afternoon!
You gave an example not inline css, but internal css with a file connection with styles. In general, you can simply specify the paths to the files. If you really like using separate snippets for this, then here it is: minifyx . This snippet has much more functionality than just including a file with styles.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question