: Assemble static site from templates? (don't want to reinvent the wheel) I have a site that is 100% static content (no php, just some javascript). There's several "blocks" like the header, menu,
I have a site that is 100% static content (no php, just some javascript). There's several "blocks" like the header, menu, footer, etc. that are the same on each page.
Rather than do a lot of copy/pasting, I was thinking of some kind of template system where I could run a CLI command (in php, perl, python, shell, whatever) and have it replace all the block tags with the actual block text.
I did see some answers in this question, but those seem oriented towards "we provide the style and layout, you provide the text". In my case, I have everything as far as layout, css, etc. - just want to do a glorified sed.
Before I invent the wheel, I was wondering if there was a tool out there already.
More posts by @Kristi941
6 Comments
Sorted by latest first Latest Oldest Best
I run apache2 for my web server, and it has a feature where you place <!--#include virtual="/cgi-bin/counter.pl" --> in the html code and it will send the code of /cgi-bin/counter.pl in the place of that tag.
For more info: httpd.apache.org/docs/2.2/howto/ssi.html
Have you tried php 'include'?
you can make a "header.php" file with all the info about the header, or just even a "menu.php" and then just make a call from the index.php
So for every other page you make you don't have to copy all your html again, just 'include' via php, this is specially handy when you are testing such included blocks and you are modifying them all the time, if you just plain html you have to modify every single one.
Check this tutorial:
www.tizag.com/phpT/include.php
There are tools for that and considering your site is mostly static, you should go for the simpler ones, otherwise you'll get more complexity without using its benefits.
Adobe Dreamweaver has a mostly WYSIWYG editor that does exactly that. You start with a styled template and you work to fill it as many times as you like. It will highlight and autocomplete for you and prevent you from damaging template areas.
Ultimately I used Smarty. Setup your template vars, fetch(), and echo. A little logic to iterate over input files and write the output to the output dir and things are working. The iteration, input/output, etc. were easier to write than to invent a new template language and this way I have all of Smarty's many features at my disposal.
www.smarty.net/
I wrote my own system for doing this called Better Templates for Everybody. I open sourced it and make it freely available. It works well enough for me, but it has never received widespread adoption.
I've also seen M4 Macros used for this purpose.
You could also consider powering your pages PHP and using #include directives.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.