[fixed] Stylesheet Pre/Post Compile events never sent
Forum rules
Only administrators can post or move items here.
Only administrators can post or move items here.
[fixed] Stylesheet Pre/Post Compile events never sent
I'm working on a module that should take the "smartyfied" css and give it to a css preprocessor such as iLess or Lessphp before writing the cache css file.
For that, I thought that the StylesheetPostCompile event was my friend, but I cannot make it work.
The problem is in the file plugins/postfilter.postcompilefunc.php / Line 28 the "switch" is waiting for a "stylesheet" string, but when I use :
debug_to_log($smarty->_current_file);
.. I have strings like "f1b38ab6e8e4130dcdcf13c16217e1138f11a830"
And the line 29 is never executed.
Seems to be buggy in 1.11 too
Hope this could help you - Thanks
For that, I thought that the StylesheetPostCompile event was my friend, but I cannot make it work.
The problem is in the file plugins/postfilter.postcompilefunc.php / Line 28 the "switch" is waiting for a "stylesheet" string, but when I use :
debug_to_log($smarty->_current_file);
.. I have strings like "f1b38ab6e8e4130dcdcf13c16217e1138f11a830"
And the line 29 is never executed.
Seems to be buggy in 1.11 too
Hope this could help you - Thanks
Re: [open] Stylesheet Pre/Post Compile events never sent
In order to make the StylesheetPostCompile event work, I suggest removing
From plugins/function.cms_stylesheet.php
And add something like
On line 324 in file plugins/function.cms_stylesheet.php
Same stuff for the PreCompile
Hope this could help..
Code: Select all
case 'stylesheet' Events::SendEvent('Core','StylesheetPostCompile',array('stylesheet'=>&$tpl_output));
break;
And add something like
Code: Select all
Events::SendEvent('Core','StylesheetPostCompile',array('stylesheet'=>&$_contents));
Same stuff for the PreCompile
Hope this could help..
Re: [open] Stylesheet Pre/Post Compile events never sent
Thanks airelibre, we will look into it.
Rolf
Rolf
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: [open] Stylesheet Pre/Post Compile events never sent
it's actually not that simple. the compile events are sent every time a template is 'compiled'. which for string resources is only once.... which is technically what we want.
This will involve a significant rework to cms_stylesheet and probably creating a new smarty resource type.
This will involve a significant rework to cms_stylesheet and probably creating a new smarty resource type.
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.
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.
Re: [open] Stylesheet Pre/Post Compile events never sent
Ok, but we only need to send the event once too, not everytime, no?
For the moment, I found a trick with placing a little "tag" in the stylesheet to identify it, but do you think this will be fixed in cmsms 2.0?
If I can help testing, let me know
For the moment, I found a trick with placing a little "tag" in the stylesheet to identify it, but do you think this will be fixed in cmsms 2.0?
If I can help testing, let me know
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: [open] Stylesheet Pre/Post Compile events never sent
Yeah, I'll figure out something to do. I think I'll have to create a separate smarty resource for stylesheets.
FYI.... The other way to do this would be to just replace the {cms_stylesheet} tag with one of your own (from your module). i.e: {MyModule action=stylesheet} or something like that.
FYI.... The other way to do this would be to just replace the {cms_stylesheet} tag with one of your own (from your module). i.e: {MyModule action=stylesheet} or something like that.
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.
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.
Re: [open] Stylesheet Pre/Post Compile events never sent
Yes I did think about that, but this would not be a proper solution I think just for 1 or 2 lines, right?
And the StylesheetPreCompile / StylesheetPostCompile remains unused.
To give you more informations, for the moment, for the module CSSPreprocessor, I use the SmartyPreCompile event, and use my own line to process the template.
It works, but I had to do conditionnal check to test if I'm in a stylesheet or not (a specific comment string in the stylesheet), and I had to ensure my code only runs once in order to not generate an infinite loop.
Maybe another solution would be to create a new event, something called "StylesheetPreWriteToFile" which would send the stylesheet just before creating the cache file?
And the StylesheetPreCompile / StylesheetPostCompile remains unused.
To give you more informations, for the moment, for the module CSSPreprocessor, I use the SmartyPreCompile event, and use my own
Code: Select all
$smarty->fetch('string:'$content);
It works, but I had to do conditionnal check to test if I'm in a stylesheet or not (a specific comment string in the stylesheet), and I had to ensure my code only runs once in order to not generate an infinite loop.
Maybe another solution would be to create a new event, something called "StylesheetPreWriteToFile" which would send the stylesheet just before creating the cache file?
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: [open] Stylesheet Pre/Post Compile events never sent
Fixed in svn.
Gotta test again with the different {cms_stylesheet} params but we should be good to go.
Gotta test again with the different {cms_stylesheet} params but we should be good to go.
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.
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.
Re: [fixed] Stylesheet Pre/Post Compile events never sent
Thank you, seems to work with my first tests.
Maybe you can help me with a "problem": with the PostCompile, Smarty gives us something like :
For in the source code
What is the proper way to get the "final" source code with smarty ?
The aim is to plug modules after all the stylesheet with smarty has been processed
Thanks
Maybe you can help me with a "problem": with the PostCompile, Smarty gives us something like :
Code: Select all
<?php echo smarty_function_uploads_url(array(),$_smarty_tpl);?>
Code: Select all
{uploads_url}
What is the proper way to get the "final" source code with smarty ?
The aim is to plug modules after all the stylesheet with smarty has been processed
Thanks
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: [fixed] Stylesheet Pre/Post Compile events never sent
Apparently you are still confused about how smarty functions.
A: A template is compiled to php code
- the precompile filter is called just before the compilation
- the postcompile filter is called just after the compilation
- compilation is only done when the template has changed (for performance reasons)
B: The php code from step A is 'rendered' by smarty into HTML (or in this case CSS).
C: (optionally) the output is 'cached' (smarty caching)
- the cache is refreshed every hour.
- In the case of CSS we do the caching ourselves.
So what you wanted is a 'post render' callback for CSS Which I don't think we ever had available.
A: A template is compiled to php code
- the precompile filter is called just before the compilation
- the postcompile filter is called just after the compilation
- compilation is only done when the template has changed (for performance reasons)
B: The php code from step A is 'rendered' by smarty into HTML (or in this case CSS).
C: (optionally) the output is 'cached' (smarty caching)
- the cache is refreshed every hour.
- In the case of CSS we do the caching ourselves.
So what you wanted is a 'post render' callback for CSS Which I don't think we ever had available.
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.
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.
Re: [fixed] Stylesheet Pre/Post Compile events never sent
Thanks for your explanation - You're right, I'm don't know Smarty compilation/caching system very well.
Yes, there is no event/callback after the CSS 'render', that's why I use the PreCompile/PostCompile event - As far as I know, it's the only way to get the CSS without having to create (and maintain) my own {cms_stylesheet} plugin. Is that right?
For the moment I use the PreCompile event, and do my own "fetch" but maybe there's a way to use the PostCompile event and get the rendered CSS code instead of the PHP source?
I know this is not directly related to v2, so thanks for your help
Yes, there is no event/callback after the CSS 'render', that's why I use the PreCompile/PostCompile event - As far as I know, it's the only way to get the CSS without having to create (and maintain) my own {cms_stylesheet} plugin. Is that right?
For the moment I use the PreCompile event, and do my own "fetch" but maybe there's a way to use the PostCompile event and get the rendered CSS code instead of the PHP source?
I know this is not directly related to v2, so thanks for your help