Categories > TinyButStrong general >

Include Javascript file with TBS fields

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
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
[include.js;mode=section;strconv=no]

b) [include] is declared as
$TBS->MergeField('include','getInclude',true);

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>";
                break;
            case "css":
                $include="<link rel=\"stylesheet\" href=\"".$app["base_url"].$file."\">";
                break;
        }   
    }
    return($include);
}

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
...
$TBS->LoadTemplate("tail.htm","+");
...
$TBS]->MergeField('field',$content);
...
$TBS->SetOption('render',TBS_OUTPUT);
$TBS->Show();
...

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....