On 13/06/2012 15:22, Dave Howorth wrote:
I'm sure there must be a way to do this, and I'm guessing it probably
involves WRAPPER, but my brain is fried. Can anybody give me a hint?

Hi Dave,

You could have a PRE_PROCESS template define a list for keywords and a MACRO to add a keyword to it:

  [% keywords = [ ];

     MACRO keyword(k)
       CALL keywords.push(k);
  -%]

And then define a WRAPPER template that looks something like this:

  <html>
    <head>
      <meta name="keywords" content="[% keywords.join(',') %]">
    </head>
    <body>
      [% content %]
    </body>
  </html>

And then in your page templates, call the keyword() macro to register each keyword:

  [% keyword('wibble') %]

The inner page templates get processed (into 'content') before the outer wrapper is invoked, so once you're in the wrapper template, you can safely print the keywords in the header and the generated content below it in the body.

If it's not convenient to call that keyword() macro explicitly then you might prefer to define a subroutine, filter, etc., to filter the page content and extract the keywords. In which case you wouldn't need the PRE_PROCESS template and could have a WRAPPER template something like this:

  <html>
    <head>
      <meta name="keywords"
            content="[% your_keyword_extracting_function(content) %]">
    </head>
    <body>
      [% content %]
    </body>
  </html>

Cheers
A

_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to