Is there an eZ way to dynamically include css & js ?

Author Message

Sébastien Antoniotti

Saturday 08 December 2007 1:19:41 am

Hi,

I'm looking for a way to dynamically include my stylesheets and js files.

By example if the current node is an article, I would like the article.css to be included in the <head> section of my page, if the current node is a product, the product.css, product1.css and maybe product.js will be included and not article.css.

So did you know an eZ way to do this ? Maybe I can create a new settings file with rules like this :

includeCSS[article]=article.css
includeCSS[product]=product1.css
includeCSS[product]=product2.css

includeJS[product]=product.js

Thanks in advance for your help !

eZ Publish Freelance
web : http://www.webaxis.fr

Paul Leclercq

Saturday 08 December 2007 2:51:35 am

Hiya Sébastien,

If you which to dynamically include stylesheets or javascript to your webpage you need to place your stylesheets or javasctpt in the stylesheet or javascript folder of your siteaccess and include them in the override of the design.ini file :
http://ez.no/doc/ez_publish/technical_manual/3_10/reference/configuration_files/design_ini

You can then use the ezini operator to extract the data:
http://ez.no/doc/ez_publish/technical_manual/3_8/reference/template_operators/data_and_information_extraction/ezini

And you create specifique conditions for each section:
You then place something like this in the override of your page_head.tpl template
for example:

{if $module_result.uri|contains('/myfolder')}
    {def $stylesheets = ezini('StylesheetSettings', 'MyFolderSiteCSS', 'design.ini')}
           {foreach $stylesheets as $stylesheet}
              <link rel="stylesheet" type="text/css" href={"stylesheet"|ezdesign} media="screen" />
           {/foreach}
    {undef $stylesheets}
{/if}

This works in the same way for javascript files. There are probably ways of reducing this but this should work.

Sébastien Antoniotti

Saturday 08 December 2007 3:07:04 am

Thanks for this solution Paul,

Good dev ;)

eZ Publish Freelance
web : http://www.webaxis.fr

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 23:17:49
Script start
Timing: Jan 18 2025 23:17:49
Module start 'layout'
Timing: Jan 18 2025 23:17:49
Module start 'content'
Timing: Jan 18 2025 23:17:50
Module end 'content'
Timing: Jan 18 2025 23:17:50
Script end

Main resources:

Total runtime1.4048 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0046 588.0625152.6406
Module start 'layout' 0.00460.0028 740.703139.4766
Module start 'content' 0.00741.3960 780.1797550.2578
Module end 'content' 1.40340.0014 1,330.437512.1250
Script end 1.4047  1,342.5625 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00280.1974160.0002
Check MTime0.00110.0804160.0001
Mysql Total
Database connection0.00060.040810.0006
Mysqli_queries1.347295.9015570.0236
Looping result0.00050.0368550.0000
Template Total1.370697.620.6853
Template load0.00170.117720.0008
Template processing1.368997.447120.6845
Template load and register function0.00010.005310.0001
states
state_id_array0.00110.080810.0011
state_identifier_array0.00240.167620.0012
Override
Cache load0.00140.0966260.0001
Sytem overhead
Fetch class attribute can translate value0.00050.034620.0002
Fetch class attribute name0.00150.107650.0003
XML
Image XML parsing0.01030.735120.0052
class_abstraction
Instantiating content class attribute0.00000.000860.0000
General
dbfile0.01100.7850210.0005
String conversion0.00000.000640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 21
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs