TinyButStrong - the PHP Template Engine
Categories > TinyButStrong general >

Include Javascript file with TBS fields

By: Fabrizio Lodi
Date: 2017-02-08
Time: 12:32

Include Javascript file with TBS fields

I'd like to

<script src="[JSFILE]"></script>

And achieve at the same times three distinct goals:
1) [JSFILE] is exploded by TBS
2) [JSFILE] is included only if the file exists
3) The content of [JSFILE] is interpreted by TBS for fields and blocks to be expanded

I was able to achieve the first two goals in this way:

a) Instead of the html script tag I use

b) [include] is declared as

c) 'getInclude' is:
function getInclude($type,$params) {
    $file=...define the file based on parameters .....

    if (file_exists($app["base_path"].$file)) {
        switch($type) {
            case "js":
                $include="<script src=\"".$app["base_url"].$file."\"></script>";
            case "css":
                $include="<link rel=\"stylesheet\" href=\"".$app["base_url"].$file."\">";

But if inside the included file I put a [field] it remain untouched ([field] or [onshow.field] or [var.field] has the same result). The same with blocks.

The order is this

What do you think it is the best way to do that? What I'm missing?

thank you
By: Fabrizio Lodi
Date: 2017-02-13
Time: 15:08

Re: Include Javascript file with TBS fields

I refactored my code, and now it works. But I have instead a problem of the order in which the included files are presented.

So I've opened another thread, because the problem is very different: http://www.tinybutstrong.com/forum.php?thr=3741

Still, is someone have a good idea other than mine....