Whow, this seems really powerful !
A priori, I think that getting the content from the file system is not slower than from the database.
I read somewhere that storing pictures in databases (as BLOBs) is huge mistake in term of speed. So, I assume that storing templates in external files is also not worse than in the DB.
In all cases, heliotrope’s plugin is very nice for development speed.
Quote from: TobyL at Feb 01, 2009, 08:20 PM
Because you use include() to fetch the template form the file system you realize that you can PHP inside the template?
Having this in your main template (fetched using @FILE:main.tpl for instance)
<?php include('header.tpl'); ?>
[*content*]
<?php include('header.tpl'); ?>
works just as well as (if not faster) than
@FILE:header.tpl
[*content*]
@FILE:footer.tpl
The other thing to be mindful about is that the result will be cached so if you change the footer.tpl file for instance the changes will not be seen until after you clear the cache in the manager.
Interesting idea. I’m not sure it wouldn’t be slower since you’d be doing three separate file accesses/reads and two calls to the PHP server versus one DB query.
-
MODX Staff
- 12,272 Posts
I think templates are cached though into the sitecache, so it’d be a one-time hit. Can someone please verify this?
Ryan Thrash, MODX Co-Founder
Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
Quote from: TobyL at Feb 02, 2009, 08:24 AM
Interesting idea. I’m not sure it wouldn’t be slower since you’d be doing three separate file accesses/reads and two calls to the PHP server versus one DB query.
Sorry,..? separate file accesses? Are you saying that with 3 @FILE: statements you are not making 3 separate file accesses? I see no difference there. As far as the 2 calls to the php engine are concerned I’m not so sure that this would add any extra overhead compared with parsing the template multiple times. The fact that you are using an include means it’s parsed by php anyway. All that’s happening is that php is ignoring the bits outside the php tags. I haven’t done any benchmarking but I suspect it’s comparing apples with apples.
Anyway I was simply pointing out something. It wasn’t a criticism.
I didn’t mean to start an argument, I was just thinking out loud. When I said "three separate file accesses/reads and two calls to the PHP server versus one DB query," I should have made it clear that I was comparing the speed of the new method to that of the standard MODx method where the whole template is in a single DB record.
No sweat. I’ve been there.
Can somebody please explain in easier terms for the not so advanced people like me what
is the difference of this method and including the template direct from the file system?
When I define my templates I use the includeFile snippet and in the template I have
a bunch of template variables for each section of the page/site... like [*footer*]
then I place chunks for the parts of the page like {{leftFooter}}, {{middleFooter}}, {{rightFooter}}
The only advantage I am seeing is that the chunks could be in the file system as well, using
the @File construct...
Website: www.mercologia.com
MODX Revo Tutorials: www.modxperience.com
MODX Professional Partner