How to include a library in a template ?

Author Message

Anthony M.

Wednesday 23 January 2008 8:41:17 am

Hi,
is it possible to include a javascript library as Ext ou Dojo in a template ?

thanks

Anthony

Pascal Specht

Friday 25 January 2008 12:48:08 am

Hi Anthony,

definitively yes:

{literal}
<script type="text/javascript">
<!--
your code
--!>
{/literal}

and also, you may use the feature in your pagelayout file:

{foreach ezini( 'JavaScriptSettings', 'JavaScriptList', 'design.ini' ) as $script}
    <script language="javascript" type="text/javascript" src={concat( 'javascript/', $script )|ezdesign}></script>
{/foreach}

Maxime Thomas

Friday 25 January 2008 4:25:59 am

Note that you will have some troubles with bracket if you would like to customize your JavaScript function with eZ variables. I mean, that the code below will fall in error :


<script type="text/javascript">
<!--
function myFunction(var1, var 2)
{

alert({$mytext});

}
--!>

Prefer this :

{literal}
<script type="text/javascript">
<!--
function myFunction(var1, var 2)
{
{/literal}
alert({$mytext});
{literal}
}
--!>
{/literal}

Maxime Thomas
maxime.thomas@wascou.org | www.wascou.org | http://twitter.com/wascou

Company Blog : http://www.wascou.org/eng/Company/Blog
Technical Blog : http://share.ez.no/blogs/maxime-thomas

Betsy Gamrat

Sunday 02 March 2008 6:24:19 am

Another way to add template data into javascript code is:

<script>
var javascript_variable={$template_variable};
{literal}
function javascript_function()
{
  alert(javascript_variable);
}
{/literal}
</script>

I have been using dojo with Smarty (http://smarty.php.net) and it is excellent. Take advantage of the themes, because they are very nice. It might be good to create a datatype that can do regular expression validation with dojo, using the "ValidationTextBox".

Good luck.

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