Dan LaManna
Dan LaManna

Reputation: 3501

Edittable Template System (Like Wordpress)

Hey all, working on creating a template system for my own open source software. I want to make it completely edittable like a wordpress theme. I was wondering what the most efficient method is in terms of fwriting/fileputcontents and overall organization of how it's done?

I mean, I'm essentially taking a file say footer.php, fopen'ing it in a+ mode and putting all of it's content into a textarea. The user then edits it, and then I would clear the files contents, and write the textareas content to the same file. Then close that file.

Perhaps there's a better way of doing it, and that's my question :P.

Thanks.

Upvotes: 0

Views: 216

Answers (2)

Dan LaManna
Dan LaManna

Reputation: 3501

Jeff Hubbard in Comment:

You should probably look into PHPTAL instead of trying to replicate the horribleness that is the WordPress template system. You'll thank me later.

Upvotes: 1

evotopid
evotopid

Reputation: 5429

I think it doesn't matter if you use: fopen, fwrite & fclose instead of file_put_contents (note that this is PHP5 only ;-) )

http://php.net/manual/en/function.file-put-contents.php

Note that this is only a shortcut, but I think it's better to use because your code will be cleaner.

The content of the file should you get with file_get_contents, because the fread() only gets 8192 bytes and than you must use a loop. (for more informations visit the docu. )

But here my version:

  1. file_get_contents('foo.bar'); // into a textarea
  2. retrive the new version
  3. and write the new file with file_put_contents(), the old one will be replaced.

Upvotes: 1

Related Questions