Page 1 of 1
CSS style in file to template and comments hack
Posted: Tue Jan 23, 2018 12:05 pm
by Cyc
Hello, I made a website
http://serwer.compsoul.pl/wino/ and I want to move locale style in file, to <style> tag in tamplate. Is there any way? Something like:
Code: Select all
{strip}
{process_pagedata}
{title assign="mainTitle"}
{content assign="mainContent"}
{share_data scope="parent" vars="mainTitle, mainContent" scope="global"}
{/strip}<!DOCTYPE html>
<__html class="index" lang="pl">
<head>
<title>{title} - {sitename}</title>
{metadata}
<style>
{cms_stylesheet|getOnlyCSS}
</style>
</head>
</__body>
Also, I would like to ask you how to delete CSS comments? Comments in CSS suggest what CMS the client uses and facilitate the potential hack.
THX!
Re: CSS style in file to template and comments hack
Posted: Tue Jan 23, 2018 4:03 pm
by paulbaker
I'm not sure on your question but you might find what you need at:
https://docs.cmsmadesimple.org/tags/cms ... stylesheet
I don't think there is a way of deleting the comments in {cms_stylesheet} controlled CSS. If it worries you I suppose you could just keep the CSS separate and link to it in your template. But then you lose the ability to edit the CSS within CMS Made Simple.
Note there are other ways of detecting which CMS is in use. It doesn't worry me that people can find out - but I do not display the CMS version number in use and I always hide the admin area.
Re: CSS style in file to template and comments hack
Posted: Tue Jan 23, 2018 4:26 pm
by Cyc
Thank you for replying! My English is not enough, but I will try to describe the problem in use simpler words.
I have template with normal {cms_stylesheet}, and result in my template is:
Code: Select all
<link rel="stylesheet" type="text/css" href="http://localhost/kdk2/tmp/cache/stylesheet_combined_68099312ce21b3a0f679fe2a2e513fa6.css" media="all" />
Is not good solutions for PageSpeed Insights. So I want import just pure css, not link, for example:
I can use
Code: Select all
{include file="cms_template:Comp CSS"}
but this solution is not convenient, because I can't use SMARTY variables. If I use "include" also have to use literal in my "include file", for example:
Code: Select all
{assign var="color" value="#fff" scope=global}
{literal}
body {
color: {/literal}{$color}{literal}
}
{/literal}
Re: CSS style in file to template and comments hack
Posted: Tue Jan 23, 2018 4:48 pm
by paulbaker
I understand your question now, but I don't know the answer. Hopefully someone else will respond.
(By the way I think having the CSS within the HTML and not a linked CSS file is horrible - the browser is forced to download the whole CSS information for every page request on your site. If it is linked as a separate CSS file the browser will only download it once and cache it for the other pages.)
Re: CSS style in file to template and comments hack
Posted: Tue Jan 23, 2018 5:03 pm
by calguy1000
@Paulbaker is correct.
MOST CSS should be in external stylesheets. This reduces the page size, and allows the browser to cache the css that is shared amongst different pages.
Inline stylesheets are OK for small sets of CSS rules (a dozen lines like) that are specific for a certain form or template... i.e: an FEU login form template may have a few CSS overrides that are inlined in the stylesheet.
but you are incorrect. If you really want to, you CAN use {include} for stylesheets and take advantage of smarty variables... it is just not recommended. You don't need {literal} tags around most CSS anymore, and have not for a long time.
WRT comments in stylesheets.... well.. that's what CSS minifiers are for. if you are really worried about it. But first I would take care of:
a. Keeping your stylesheets in separate files (DesignManager does that for you).
b: reducing requests for stylesheets (DesignManager helps with that)
c: allowing browsers to cache stylesheets (See the sample .htaccess file distributed with CMSMS in doc/htaccess.txt)
d: Enabling compression for all of the data you send... (mod_deflate etc).
Re: CSS style in file to template and comments hack
Posted: Tue Jan 23, 2018 8:34 pm
by Cyc
Ok, in that case, I will use the old way. Maybe {strip} tag is not required when I importing CSS, but in JS importing is necessary. I have last question, is there a way doing one line code in template? For example:
{strip}
[template code]
{/strip}
Re: CSS style in file to template and comments hack
Posted: Wed Jan 31, 2018 2:42 am
by aviapic
To delete the comments in compiled cms_stylesheet,
create UDT named : clean_StylesheetPostCompile
Code: Select all
$params['stylesheet'] = preg_replace('#/\*(.*)\*/|\n|\r#sU', '', $params['stylesheet']);
then in event manager, StylesheetPostCompile, add this UDT.
Clear cache and verify you stylesheet in frontend.
---
To strip css in stylesheet
Code: Select all
[[strip]] your css code [[/strip]]
--
To strip code in template : cf smarty
Code: Select all
{strip}...code {plugin_name|strip} or {module_name|strip} for modules or plugin not compatible with strip tag like 'content' plugin {{content}|strip} {/strip}
----
To strip inline js code :
cf module CGExtensions
----
To combine js file :
cf module CGExtensions and read his documentation about the included function cgjs_render
hope it's help
Re: CSS style in file to template and comments hack
Posted: Fri Feb 02, 2018 9:26 am
by velden
Cyc wrote:
...
I can use
Code: Select all
{include file="cms_template:Comp CSS"}
but this solution is not convenient, because I can't use SMARTY variables. If I use "include" also have to use literal in my "include file", for example:
Code: Select all
{assign var="color" value="#fff" scope=global}
{literal}
body {
color: {/literal}{$color}{literal}
}
{/literal}
If you 'enclose' your curly brackets with spaces you don't need the {literal} tags. So your own example should already work without the literal tags. Note this is not true for rather old versions of CMSMS.
Code: Select all
{assign var="color" value="#fff" scope=global}
body {
color: {$color}
}