Call javascript functions in template ? [to use ajax]

Author Message

Eder Silva

Wednesday 04 July 2007 3:31:03 pm

Hello,
I want use ajax in some templates...

How can I call javascript functions in template ?

I have this code:

<head>
<script type="text/javascript" src="/dajax/lib/prototype.js"></script>
<script type="text/javascript" src="dajax/src/scriptaculous.js"></script>
</head>

But the problem is, a template pages doesn't have <head></head>, only pagelayout.tpl have it, I try insert this lines in pagelayout.tpl, but my template doesn't work...

I need use this js functions in my template...

My template have this code:

<ul id="movies_list">
        <li id="movie_1">test 1</li>
        <li id="movie_2">test 2</li>
</ul>
        <script type="text/javascript">
            Sortable.create('movies_list');
        </script>

Thanks for any help !

[eZ 3.9]

Bruce Morrison

Wednesday 04 July 2007 6:27:44 pm

Hi Eder

You have (at least) 2 options

Add the scripts to the design.ini of the siteacesss you want them used in

[JavaScriptSettings]
JavaScriptList[]=dajax/lib/prototype.js
JavaScriptList[]=dajax/src/scriptaculous.js

This method assumes they are under design/site_design/javascript directory (e.g. design/site_design/javascript/dajax/lib/prototype.js) and will add them to the head of each page.

The other method is to add them to the template e.g.

{run-once}
<script type="text/javascript" src={"javascript/dajax/lib/prototype.js"|ezdesign}></script>
<script type="text/javascript" src={"javascript/dajax/src/scriptaculous.js"|ezdesign}></script>
{/run-once}

<ul id="movies_list">
       <li id="movie_1">test 1</li>
       <li id="movie_2">test 2</li>
</ul>
       <script type="text/javascript">
           Sortable.create('movies_list');
       </script>

The run-once tags are there so if the template is used multiple times the javascripts are only included once. They may not be necessary.

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Eder Silva

Friday 13 July 2007 8:22:51 am

Thanks so much !!

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 15:55:11
Script start
Timing: Jan 18 2025 15:55:11
Module start 'layout'
Timing: Jan 18 2025 15:55:11
Module start 'content'
Timing: Jan 18 2025 15:55:11
Module end 'content'
Timing: Jan 18 2025 15:55:11
Script end

Main resources:

Total runtime0.0189 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0076 589.1797152.6406
Module start 'layout' 0.00760.0033 741.820339.4766
Module start 'content' 0.01090.0060 781.296993.4922
Module end 'content' 0.01690.0020 874.789134.3047
Script end 0.0189  909.0938 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.003317.4851140.0002
Check MTime0.00126.6052140.0001
Mysql Total
Database connection0.00105.139010.0010
Mysqli_queries0.003317.443530.0011
Looping result0.00000.068110.0000
Template Total0.00168.310.0016
Template load0.00094.582610.0009
Template processing0.00073.678010.0007
Override
Cache load0.00063.137910.0006
General
dbfile0.00126.460180.0002
String conversion0.00000.041640.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