Use specific Css in an extension

Author Message

Patrice DUCLAUD

Wednesday 13 December 2006 6:25:44 am

Hi all,

In an extension, i need to define a css file, but i don't know how to make this css file used by my template. (ezpublish 3.8.11 - php 4.3)

my css file is located here :
extension/MyExtension/design/standard/stylesheets/MyExtension/MyCss.css

my design.append.ini.php file in extension/MyExtension/settings/ contains
...
[Stylesheetsettings]
MyExtension=extension/MyExtension/design/standard/stylesheets/MyExtension/MyCss.css
...

i've cleared the cache
but my design don't use MyCss.css

I'm sure i do something wrong ;-( but what ?

Thanks for help

Patrice

Claudia Kosny

Wednesday 13 December 2006 1:44:31 pm

Hi Patrice

I have never tried it, but shouldn't this be:

[ExtensionSettings]
DesignExtensions[]=MyExtension

[StylesheetSettings]
CSSFileList[]=stylesheets/MyExtension/MyCss.css

And your pagelayout.tpl needs to have something like this in the <style> part to get the above working:

{section var=css_file loop=ezini( 'StylesheetSettings', 'CSSFileList', 'design.ini' )}
    @import url({concat( 'stylesheets/',$css_file )|ezdesign});
{/section}

The problem with this is that it will load all CSS files for all active extensions.

Again, I have never tried it, so no guarantees...

Claudia

Patrice DUCLAUD

Thursday 14 December 2006 3:09:56 am

Hi Claudia,

Thanks for your reply, i've done something which works fine, but need certainly to be improved.

i've created :
<b>a css file</b> called MyModule.css located in /extension/MyModule/design/standard/stylesheets/MyModule/

<b>an ini file</b> located in /extension/MyModule/settings/MyModule.ini
with this code

[StylesheetsSettings]
CSSFile=/extension/MyModule/design/standard/stylesheets/MyModule/MyModule.css

<b>a function in MyModule.php </b> located /extension/MyModule/modules/MyModule/class/ in a php class MyModule

MyModule.php contains the class and function of my module.

function MyModuleInit ( $Section, $Var) {
  $Value=array();
  $MyModuleINI =& eZINI::instance( 'MyModule.ini');
  $Value['Value']=$MyModuleINI->Variable($Section, $Var);
  return array( 'result' => $Value);
}

This function read MyModule.ini and returns $Value corresponding to parameters $Section and $Var. (yes, yes ... it's seems to be an eZini look like ;-) )

In MyPageLayout.tpl

i've just do , between <head>..</head>:

{if ne($ui_component,'content')}   
  def $Css=fetch( $ui_component, concat($ui_component,'INI',
                        hash( 'Section', 'StylesheetsSettings', 
                                 'Var', 'CSSFile'))}
  <style type="text/css">
    {foreach $Css as $css}
       @import url("{$css}");
    {/foreach}
    {undef $Css}
  </style>
{/if}

The use of $ui_componnent allow me to look for css only if i access MyModule, or a Module which contain a function called ModuleINI ... $ui_component in my case = MyModule otherwise 'content' which is the default ezpublish acces content ... !
<i>
I use only one css file in my module MyModule.
All the Name used in code and file must be MyModule.
In MyModule.ini, you must use StylesheetsSettings and CSSFile
and this work could be certainly used with another Module
</i>

In MyPageLayout.tpl i can see

<style type="text/css">  
@import url("/extension/MyModule/design/standard/stylesheets/MyModule/MyModule.css");
</style>

i hope i'm clear enough (sorry for my english) and thanks for your comments.

Patrice

Claudia Kosny

Thursday 14 December 2006 9:51:37 am

Hi Patrice

The way I understand it the problem is the path of the css file as the html code to include it looks fine otherwise. Unfortunately I don't know an easy and safe way to create a valid path out of the path you have. The usual suspects ezurl() and ezroot() will not work, because your css file is not a view of a module (which is ok, it shouldn't be).
ezdesign() works only if you tell ez that your extension contains a design directory by setting this in the design.ini.append.php of your extension. This would be the easiest way, but I don't know whether this is an option for you as this would mean that template overrides in this directory would override other templates no matter the ui_component (I believe).

I haven't worked with ui_component yet, so I don't know what is possible there or not. Sorry, but itr looks like I can't help you.

Good luck

Claudia

Pascal Specht

Friday 22 June 2007 7:33:35 am

Hello,

I had a similar problem (using eZ Publish 3.9.2), the CSS never really wanted to show up...

In my case, the UNIX files on the server had been created remotely through SVN update, and had a wrong file permission. Doing a chmod -R a+x myextension solved the problem.

-Pascal

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 19:11:35
Script start
Timing: Jan 18 2025 19:11:35
Module start 'layout'
Timing: Jan 18 2025 19:11:35
Module start 'content'
Timing: Jan 18 2025 19:11:35
Module end 'content'
Timing: Jan 18 2025 19:11:35
Script end

Main resources:

Total runtime0.0164 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0055 590.2266152.6250
Module start 'layout' 0.00550.0032 742.851639.4453
Module start 'content' 0.00880.0056 782.296993.4609
Module end 'content' 0.01440.0020 875.757838.3047
Script end 0.0164  914.0625 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002615.5967140.0002
Check MTime0.00127.4662140.0001
Mysql Total
Database connection0.00084.992510.0008
Mysqli_queries0.002917.853930.0010
Looping result0.00000.072710.0000
Template Total0.00169.710.0016
Template load0.00085.017210.0008
Template processing0.00084.669910.0008
Override
Cache load0.00063.547810.0006
General
dbfile0.00116.611680.0001
String conversion0.00000.037840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs