Categories > TinyButStrong general >

Include or not to include (I was thinking (oh no, not again))

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: mgb
Date: 2007-12-13
Time: 14:55

Include or not to include (I was thinking (oh no, not again))

Hello Y'all,

I am slowly working up a quite complex tbs infrastructure with a lot of
[onload;file=[var.__header];noerr]
...
[subtpl;file=[var.__galleryboxtpl];noerr]
...
[onload;file=[var.__footer];noerr]
These different files have between 2-4 more and less complicated  blocks.
I of course use the cache module in tbs which is great.
But it does have some limitations. For instance if when a user is logged in and is handling his user data.
What I was thinking was to make a lot of
$__tbs->Source = $__header;
// do merging/caching
$page = $__tbs->Source;
$__tbs->Source = $__galleryboxtpl;
// do merging/caching
$page .= $__tbs->Source;

/*
* do dynamic merging here
* and add it to $page.
*/

$__tbs->Source = $__footer;
// do merging/caching
$page .= $__tbs->Source;

echo $page;
This is a crude example but I hope you understand.
Are anyone doing this already?
What are the pro/con's?

Thanks in advance.
mgb
By: sheepy
Date: 2007-12-14
Time: 05:18

Re: Include or not to include (I was thinking (oh no, not again))

In a sense, it's just a matter of doing it with template or with PHP.

The only meaningful difference I can think of is putting it in html make the template clearer, since you mark the include right there.  Easier for designers to work with.  While putting it in PHP allows more control - fallback template, customised error message, common template pre-conditioning, etc.

I personally tend to put it in template, esp. if there are no other needs.  Speed different is too minor to be considered.

Hope this will help.
By: mgb
Date: 2007-12-14
Time: 11:57

Re: Include or not to include (I was thinking (oh no, not again))

Hi sheepy,
And thanks for the input. I wasn't too concerned about speed.
My site gets 30/s hits so this should not be a problem. Especially if I use caching.
I use a lot of includes is because we have a lot of repeating content on the site - menu's and such.
What I was thinking was for instance:
Our main menu is quite complex with submerges, bells and whistles :)
What I was suggesting was to cache the menu template one separately. So that it would always look the same on all sites (no matter when the page is cached) and also would not need to be merged every time a non-cached page gets hit.
In that way I could have cached elements on the site together with on the fly merges.
I don't know if this makes sense to you, but at the moment it does to me :)

Maybe a feature request could be to have something like:
$__tbs->MergeBlock('block',Source [,Query[,(bool) cache=true]);
so that if cache is set to false the merge would be done, but the cached file would still include the tbs block and need to be merged on future hits.
I don't know if this would be to complex to do, I might very well be.
Maybe it would be best to separate it out into its own plug-in?

Just some thoughts, feel free to flame :)
By: Skrol29
Date: 2007-12-17
Time: 01:27

Re: Include or not to include (I was thinking (oh no, not again))

hi Mgb,

Such a feature was in study. In fact it can be done by a plug-in but it has to be done.

You can also do another way : use sub-script for caching sub-templates.
Example:
[onload;script=manage_cache.php;subtpl;action=menu]
And then you sub-script manage the merging and the caching. action=menu is a custom parameter that you can retrieve inside your subscript in order to decide which content to merge.



By: mgb
Date: 2007-12-17
Time: 09:11

Re: Include or not to include (I was thinking (oh no, not again))

Hi Skrol29,
Thats a nifty work-around, I hadn't thought of using script like that at all :)

About the plug-in I think I will devote some of my Christmas spirit/time to understanding how they work. Who knows, maybe I can actually do something productive for the tbs community other than ask questions :)