keybase
[m6w6/m6w6.github.io] / _posts / 2004-08-02-javascript-flexy.md
1 ---
2 title: Javascript & Flexy
3 author: m6w6
4 tags:
5 - PHP
6 ---
7
8 If you ever used [Flexy](http://pear.php.net/package/HTML_Template_Flexy),
9 which I consider a really great TE, you have most probably already stumbled
10 across Flexy's inability to step into `<script>` blocks.
11
12 A really easy method to overcome this problem is to define scriptOpen and
13 scriptClose properties in your base objects outputted by Flexy:
14
15 ```php
16 <?php
17 class FlexyObject {
18 var $scriptOpen = "\n<script type="text/javascript"> <!--\n";
19 var $scriptClose = "\n//--> </script>n";
20 var $scriptData = "var foo = 'bar';";
21 }
22 ```
23
24 Outputting above object with the following template wont work:
25
26 ```html
27 <html>
28 <script type="text/javascript">
29 {scriptData:h}
30 </script>
31 </html>
32 ```
33
34 Instead:
35
36 ```html
37 <html>
38 {scriptOpen:h}
39 {scriptData:h}
40 {scriptClose:h}
41 </html>
42 ```
43
44 ...works like a charm... ;)
45
46 Alan said, Flexy wont step into Javascript blocks because that caused
47 massive problems with the Smarty convertor...