Dec 04, 2008, 01:07 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Search via SMF or Google: modx forums all of modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
News:Read what MODx Developers say: MODx Dev. Blogs
Pages: [1]   Go Down
  Print  
Author Topic: store templates in file system?  (Read 10767 times)
0 Members and 1 Guest are viewing this topic.
erotte
Jr. Member
*
Posts: 13


« on: May 01, 2006, 05:53 PM »

Hi there,
a simple question:
why are templates stored to the database?
It is much more easy  to edit a template when its stored in the file system.

In cmsimple theres a way to call templates from file system via an include.

Is there a similar way in modx?


Logged
OpenGeek
MODx Co-Founder
Foundation
*
Posts: 5,054


looking a little more like my avatar again...


WWW
« Reply #1 on: May 01, 2006, 06:00 PM »

Templates are stored to the database because the folks who originally designed Etomite did it that way.  Content in the database vs. the filesystem is an argument as old as content management.  I personally keep copies of all my templates in the filesystem and edit those, then copy and paste in the manager.  But it's just as easy to write a snippet to include your templates from the file system, then simply use a single template in MODx to wrap it with anything else you might not want in the template (might be a blank template with nothing but a snippet call in it).  I believe someone has done something similar and posted about it here, but I'd have to search for it.
Logged

Jason Coward
MODx Co-Founder
xPDO Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
The spirit of a warrior is not geared to indulging and complaining, nor is it geared to winning or losing. The spirit of the warrior is geared only to struggle, and every struggle is a warrior's last battle on earth. Thus the outcome matters very little to him. In his last battle on earth a warrior lets his spirit flow free and clear. And as he wages his battle, knowing that his intent is impeccable, a warrior laughs and laughs.
  — don Juan Matus
doze
Coding Team
*
Posts: 3,237


....Boom!


« Reply #2 on: May 02, 2006, 04:31 AM »

There is allready ready made snippet for this (to have templates/snippets/whatever in filesystem and just include them at manager), and there is also discussion about this in some threads, see here for example and do a seach with "include" for more information.
Logged

MODxWiki || Please, list wiki worthy material here!
Marschant
Full Member
***
Posts: 133


« Reply #3 on: May 02, 2006, 04:44 AM »

My approach is to create a "GLOBAL" template, well that's what I called it anyway, containing the following:

Code:
[[includeFile?&phpfile=[*templatePath*]/template/template.php]]

Within a document I have a template variable called templatePath that I've setup with @INHERIT as the default property. I then set each master folder or documents "templatePath" TV to something like "assets/issues/march" or whatever you want to call it.

In the file system I have "assets/issues/march/template/template.php" and sub-folders containing all my css and images. Within the php template I use the TV value for linking to stylesheets and images, and in certain cases have found that I need to set a php path variable as well.

Not sure how complicated your setup is going to be but I've found this works really well for me. You see I'm doing a monthly ezine and each issue has a different feel so managing multiple templates with the Manager was a nightmare, with this approach I use a single template and change the path to what it includes - sweet - no more stressing!!!

If you need some more help please don't hesitate to ask.
Logged
erotte
Jr. Member
*
Posts: 13


« Reply #4 on: Jun 03, 2006, 08:40 AM »

My approach is to create a "GLOBAL" template, well that's what I called it anyway, containing the following:

Code:
[[includeFile?&phpfile=[*templatePath*]/template/template.php]]


Ups, one month ago - but many thanks, this seems to be a good solution!

Greetings
E.
Logged
gunner
Jr. Member
*
Posts: 12


« Reply #5 on: Jun 07, 2006, 03:49 PM »

I am trying to implement this with not much luck. Can you describe the process, what goes where to make this call? TIA
Logged
Marschant
Full Member
***
Posts: 133


« Reply #6 on: Jun 08, 2006, 03:06 AM »

I am trying to implement this with not much luck. Can you describe the process, what goes where to make this call? TIA

My approach is the following:
  • Create a new directory within the assets/templates folder
  • Create your master template as template.php or whatever you want to call it. This is your html with any references to stylesheets, scripts, template variables or placeholders within it.
  • Search for the includeFile snippet and install it or use the code pasted below
  • Setup a new template within the manager insert a includeFile snippet call (see below)
  • Modify any existing template variables within the manager that will need access to this template
  • Create a new document that uses the newly created template, add some content, publish and browse to it, hopefully everything worked out well

includeFile Snippet
Code:
# For example to include cutenews, you can use
# [[includeFile?template=nicetemplate&phpfile=cutenews/show_news.php]].
# You can offcourse pass any variable to the snippet to use for the included file.

if ( !isset($phpfile) || $phpfile == "" ) return "No file specified."; //check if there's a file given.

//Start the buffer
ob_start();

//include
include $phpfile;

//get contents from the buffer
$ob_contents = ob_get_contents();

//and kill/delete the buffer
ob_end_clean();

//return it to MODX.
return $ob_contents;

snippet call within a newly defined template in the manager

Code:
[[includeFile?&phpfile=[*templatePath*]/template/template.php]]

or

Code:
[[includeFile?&phpfile=assets/templates/mytemplate/template.php]]

I use a templatePath variable because I've moved all my resources to "assets/issues/year/month" because each monthly issue I publish has a different look and feel to it. You probabely won't need to worry about something like this.

If you need me to post the actual content of template.php please let me know.
Logged
gunner
Jr. Member
*
Posts: 12


« Reply #7 on: Jun 08, 2006, 03:41 PM »

Worked perfectly! Thanks so much.
Logged
Marschant
Full Member
***
Posts: 133


« Reply #8 on: Jun 09, 2006, 03:13 AM »

Glad I could help!
Logged
MikeT
Jr. Member
*
Posts: 30


___me_sleepy___


« Reply #9 on: Jul 16, 2006, 07:49 PM »

I was wondering if you could link the template code, and got directed here by the ever helpfull Sottwell.

Thanks Marschant, read your post and even though I could not get it to work the way you described (my issues!) I found it helped my brain spark with some new ideas.

I re-read some of the MODx documentation and found the TV @FILE.

What I did for a solution was:

1. Create a TV called [*templatePath*]
2. Default value @FILE assets/templates/index.html (or to where you file is)
3. Set the Template Access
4. Then put the TV [*templatePath*] in your template code

The great thing about this is you can then edit your code within a text editor and because it is linked you do not have to continue to cut and paste all the time.

This works perfectly for me and my workflow.

I use Style Master and Skedit.

Stylemaster lets you use any on line document to preview what your CSS looks like from with Stylemaster app itself. So the way I can work is:

1. Linked template code to MODx.
2. Style master uses localhost/mysite/index.php?id=4 (non_friendly) as my preview doc.
3. Skedit to edit code.

So it works as a nice little loop. However I am having trouble with the page sticking in the cache.

Any suggestions to this would be great!

Thanks all.

Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF 1.1.4 | SMF © 2005, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!