0

How would you set an include file dynamically from a set variables in a php file?

<body>
    {onload;file={tplvar.absopath}}
</body>

So, once the template is loaded, $tbs->LoadTemplate($tpl) the file should produce the html built on the file absopath points to.

  • @FunkFortyNiner down voting for family tree question? is this stackoverflow or NCIS? –  Mar 05 '18 at 23:38
  • you shouldn't use your sock puppet to upvote the post here. – Funk Forty Niner Mar 05 '18 at 23:40
  • @FunkFortyNiner I am lost please exit my thread because your harassing me now –  Mar 05 '18 at 23:48
  • The word is "you're" as in "you are", not "your" as in "ownership". Btw, if anyone's at fault here, it's you. I have nothing to feel guilty about. Or, which "Kevin" am I speaking with here? You, or [you](https://stackoverflow.com/users/4108487/kevin-wiggins)? – Funk Forty Niner Mar 05 '18 at 23:51

2 Answers2

1

Parameter file can insert the contents of a file inside the TBS template.

Examples

PHP side:

$filename = 'header.html'; 

Template side:

[onload;file=[var.filename]] 

See parameter file

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Skrol29
  • 5,402
  • 1
  • 20
  • 25
  • what if the $filename='header.html' is defined inside of a block? – Kevin Wiggins Mar 05 '18 at 23:20
  • i guess you could expose the $filename to a global space but is there a way to send that filename with the template? versus giving it global access? – Kevin Wiggins Mar 05 '18 at 23:30
  • `[onload;file=[var.filename]] ` will be merged when the template is loaded, that is before any MergeBlock(). This is better for performance. While `[onshow;file=[var.filename]] ` will be merged before Show(), that is after any MergeBlock(). – Skrol29 Mar 06 '18 at 23:19
  • In the snippet, `$filename` is supposed to be a global variable. But you can use local variables using VarRef. See http://www.tinybutstrong.com/manual.php#php_varref – Skrol29 Mar 06 '18 at 23:22
0

If you have a variable containing a filename, then you can use that with require or include (with or without _once).

For example:

<?php
$template = __DIR__.'/templates/header.php';
require_once $template;

sort of thing.

This would be an extremely crude way of including a template file, but it is as simple as you can get.

Richard A Quadling
  • 3,769
  • 30
  • 40
  • Check the edits. I need to dynamically create the include once the template is loaded from a tinybutstrong class object –  Mar 05 '18 at 22:29