Forums / Setup & design / Is there an eZ way to dynamically include css & js ?

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

eZ debug

Timing: Jan 19 2025 21:29:30
Script start
Timing: Jan 19 2025 21:29:30
Module start 'content'
Timing: Jan 19 2025 21:29:30
Module end 'content'
Timing: Jan 19 2025 21:29:31
Script end

Main resources:

Total runtime0.2203 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0092 590.2344180.8125
Module start 'content' 0.00920.0106 771.046994.0547
Module end 'content' 0.01980.2004 865.1016526.3750
Script end 0.2203  1,391.4766 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00391.7686200.0002
Check MTime0.00160.7412200.0001
Mysql Total
Database connection0.00080.370310.0008
Mysqli_queries0.129558.75451410.0009
Looping result0.00140.62211390.0000
Template Total0.199690.610.1996
Template load0.00110.488310.0011
Template processing0.198690.113310.1986
Override
Cache load0.00070.304910.0007
Sytem overhead
Fetch class attribute can translate value0.00080.372510.0008
XML
Image XML parsing0.00030.114410.0003
General
dbfile0.028913.1263200.0014
String conversion0.00000.004130.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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