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.