Simon H
Simon H

Reputation: 21005

Docpad: generate php output file

I'm using Docpad to generate static files for a standard, LAMP-hosted site. I want to implement password access one of the pages, so my intention was to use a php page with this password_protect script.

I've setup my docpad 'layout' to add <?php include... to the relevant page, and use .php as the suffix on the particular document, but the output I'm getting is .html.

My reading of the docs is that Docpad considers php as a pre-processor, not as an output type, so is there anything I can easily do to save myself hand-renaming the file when I deploy?

Upvotes: 0

Views: 138

Answers (2)

user7363501
user7363501

Reputation: 31

Are you using DocPad layouts? It seems (at least now) that layout extensions take priority over resource extensions. Maybe using a layout with php extension will solve the problem.

How to use one layout for multiple extensions

If you don't want to duplicate a layout file (which defeats the purpose of layouts), you could create a symbolic link to the parent layout, like so (on linux in the layout folder):

ln -s layoutname.html.eco php-layoutname.php.eco

Don't forget to update the layout property in the frontmatter of your php files afterwards!

Upvotes: 0

kfields
kfields

Reputation: 56

Yeah, it's kind of strange. I thought the extension after the basename would be the output extension. This fixed it for me. Put it under events in your docpad config file or as a method in a plugin.

  writeBefore: (opts) ->
    {collection, templateData} = opts
    collection.forEach (file,index) ->
      ext = file.get('extensions')[0]
      if ext == 'php'
        outDirPath = file.get('outDirPath') 
        basename = file.get('basename')
        outFilename = basename + '.php'
        file.set('outPath', outDirPath + '/' + outFilename)

Upvotes: 1

Related Questions