Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Here's a very big gun, there's your foot: PHP support in Nikola

I am a ve­ry big pro­po­nent of sta­tic si­te ge­ne­ra­tor­s. I would not ha­ve bo­the­red wri­ting Niko­la othe­rwi­se. But the­re is alwa­ys that fee­ling that ma­y­be the­re is so­me li­ttle thing whi­ch is hard to im­ple­men­t, like a con­tact for­m.

And le­t's fa­ce it, the ea­siest way to sol­ve so­me of tho­se things is by sti­cking a few li­nes of PHP in your HT­M­L.

So, if you rea­lly want to, you can do it. I thi­nk Niko­la (gi­thub mas­te­r) is the first sta­tic si­te ge­ne­ra­tor that su­ppor­ts php co­de. He­re's ho­w:

  1. Add php to your pa­ge_­com­pi­lers (be­cau­se I wi­ll ne­ver put it the­re by de­faul­t):

    post_compilers = {
        "rest": ('.txt', '.rst'),
        "markdown": ('.md', '.mdown', '.markdown'),
        "textile": ('.textile',),
        "txt2tags": ('.t2t',),
        "bbcode": ('.bb',),
        "wiki": ('.wiki',),
        "ipynb": ('.ipynb',),
        "html": ('.html', '.htm'),
        "php": ('.php'),
  2. Add php pos­ts or pa­ges to your pos­t_­pa­ges:

    post_pages = (
        ("posts/*.txt", "posts", "post.tmpl", True),
        ("posts/*.php", "posts", "post.tmpl", True),
        ("stories/*.txt", "stories", "story.tmpl", False),
        ("stories/*.php", "stories", "story.tmpl", False),
  3. Crea­te a php pos­t:

    nikola new_post posts/foo.php
  4. Put php in the­re:

    .. date: 2013/04/16 09:57:09
    .. title: php test
    .. slug: foo
    Print "Hello, World!";

Build the si­te as usua­l, and you should end up wi­th a pa­ge wi­th PHP ex­ten­sio­n, that has that PHP in the "con­ten­t" area, so it wi­ll fo­llow your si­te's the­me. Of cour­se you can't do things like add HTTP hea­ders and su­ch, but he­y, read the ti­tle.

James Mills / 2013-04-16 23:56:

Holy crap!!! *BOOM!!!*

Contents © 2000-2023 Roberto Alsina