slm
slm

Reputation: 16416

Can you add custom html tags to Jekyll?

I'd like to generate some template pages using Jekyll which will then be used by a Perl script making use of the HTML::Template Perl module. Is it possible to get Jekyll to leave HTML::Template's tags alone and just ignore them completely?

For example:

<tr>             <td>Name:               </td>  <td><TMPL_VAR NAME=NAME> </td> </tr>
<tr class="alt"> <td>Email:              </td>  <td><TMPL_VAR NAME=EMAIL></td> </tr>

I want the page to get rendered as a .html file with the <TMPL_VAR NAME=...> bits left alone, later on a backend Perl script would make use of this file as a template file and would fill in the spots where the <TMPL_VAR NAME=...> bits are.

Upvotes: 1

Views: 1470

Answers (2)

slm
slm

Reputation: 16416

Using what I learned from another question I asked & answered on stackoverflow, these appear to be your 3 options. One of which @Alan W. Smith stumbled onto as well in an answer to this question.

Option #1: - HTML::Template has a switch called vanguard_compatibility_mode...from the perldocs

vanguard_compatibility_mode - if set to 1 the module will expect to see s that look like %NAME% in addition to the standard syntax. Also sets die_on_bad_params => 0. If you're not at Vanguard Media trying to use an old format template don't worry about this one. Defaults to 0.

Option #2 - HTML::Template also supports embedding the template tags in comment blocks so that your code is HTML compliant, like so: <!-- TMPL_NAME NAME=FNAME -->

Again from the perldocs:

If you're a fanatic about valid HTML and would like your templates to conform to valid HTML syntax, you may optionally type template tags in the form of HTML comments. This may be of use to HTML authors who would like to validate their templates' HTML syntax prior to HTML::Template processing, or who use DTD-savvy editing tools.

<!-- TMPL_VAR NAME=PARAM1 -->

This 2nd option didn't work originally for me until I set the die_on_bad_params => 0 for the constructor.

Option #3: Change the name of your Jekyll file from .md (markdown) to .html (vanilla html). This option get's around Jekyll's use of ReXML for it's XML parser. I'm not sure but if you switched from using ReXML to Nokogiri, I think that too would get around this issue, but I'm not entirely sure you can even reconfigure Jekyll in this manner.

Conclusion: Ultimately I think Option #2 is the best one to use, given it doesn't limit your ability to use .md files within Jekyll.

Upvotes: 1

Alan W. Smith
Alan W. Smith

Reputation: 25435

You can leave the HTML (both standard and your Perl HTML::Template sets) as is by creating your source pages with a .html extension. When you do that, jekyll (as of 0.11.2 at least) won't mess with the source HTML. You can still use YAML front matter and drop in liquid tags. For example, this would work as a source file with a .html extension.

---
layout: default
title: This is the post title
categories: ["miscellaneous"]
---

{{ page.title }}

<table>
<tr>             <td>Name:  </td>  <td><TMPL_VAR NAME=NAME> </td> </tr>
<tr class="alt"> <td>Email: </td>  <td><TMPL_VAR NAME=EMAIL></td> </tr>
</table>

From there, you can pass to your secondary processing with your HTML::Template tags intact.

Upvotes: 2

Related Questions