Topic: store templates in file system?  (Read 13706 times)

Pages: [1]   Go Down

#1: 1-May-2006, 05:53 PM

erotte
Posts: 13

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?


#2: 1-May-2006, 06:00 PM

Foundation

OpenGeek
MODx Co-Founder
Posts: 6,985

damn accurate caricatures...

WWW
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.
Jason Coward
MODx Co-Founder
xPDO Founder
CTO @ Collabpad
work productively.
work intelligently.
work together.
Light is just a vibration of a note too. Everything is. You've got to keep that in mind.
  Frank Zappa

#3: 2-May-2006, 04:31 AM

Coding Team

doze
Posts: 4,111

....Boom!

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.
New MODx wiki! Please help up with documentation efforts! || Old Wiki

"He can have a lollipop any time he wants to. That's what it means to be a programmer."

#4: 2-May-2006, 04:44 AM

Marschant
Posts: 133

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.

#5: 3-Jun-2006, 08:40 AM

erotte
Posts: 13

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.

#6: 7-Jun-2006, 03:49 PM

gunner
Posts: 12

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

#7: 8-Jun-2006, 03:06 AM

Marschant
Posts: 133

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.

#8: 8-Jun-2006, 03:41 PM

gunner
Posts: 12

Worked perfectly! Thanks so much.

#9: 9-Jun-2006, 03:13 AM

Marschant
Posts: 133

Glad I could help!

#10: 16-Jul-2006, 07:49 PM

MikeT
Posts: 30

___me_sleepy___

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.

Pages: [1]   Go Up
0 Members and 1 Guest are viewing this topic.