CSS style in file to template and comments hack

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
User avatar
Cyc
Forum Members
Forum Members
Posts: 91
Joined: Wed Nov 18, 2015 11:54 pm
Location: Poland

CSS style in file to template and comments hack

Post 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!
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Location: Maidenhead, UK
Contact:

Re: CSS style in file to template and comments hack

Post 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.
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation

CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
User avatar
Cyc
Forum Members
Forum Members
Posts: 91
Joined: Wed Nov 18, 2015 11:54 pm
Location: Poland

Re: CSS style in file to template and comments hack

Post 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:

Code: Select all

body {
   bla: bla;
}
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}
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Location: Maidenhead, UK
Contact:

Re: CSS style in file to template and comments hack

Post 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.)
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation

CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: CSS style in file to template and comments hack

Post 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).
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
Cyc
Forum Members
Forum Members
Posts: 91
Joined: Wed Nov 18, 2015 11:54 pm
Location: Poland

Re: CSS style in file to template and comments hack

Post 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}
aviapic

Re: CSS style in file to template and comments hack

Post 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

Code: Select all

{jsmin}..your js code.{/jsmin}
----
To combine js file :
cf module CGExtensions and read his documentation about the included function cgjs_render

hope it's help
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: CSS style in file to template and comments hack

Post 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}
}
Post Reply

Return to “CMSMS Core”