Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm using HTML::Template to customize a bunch of SVGs. This works pretty well, except I now need to edit the SVGs in Illustrator to change a couple of elements. Unfortunately, I can't open my template files as SVGs because the HTML::Template tags cause syntax errors.

Is there a good way to automatically convert my templates so that they use the HTML comment style of HTML::Template tags? I think if I do this then I'll be able to open the files in Illustrator. However, I've got quite a few of them, and many are large (>1 MB), so I'd like to automate this if at all possible.

Thanks!

--TWH
  • Comment on Convert HTML::Template tags to valid HTML comments

Replies are listed 'Best First'.
Re: Convert HTML::Template tags to valid HTML comments
by tobyink (Canon) on Jan 03, 2012 at 09:25 UTC

    How complex are your SVG customisations? Unless it's going to be a lot of work, I'd drop HTML::Template, and just do DOM manipulation with XML::LibXML.

    Edit your SVGs, and add some xml:id attributes to the elements that need altering. Then in Perl, use XML::LibXML and XPath selectors to find those elements and alter them.

Re: Convert HTML::Template tags to valid HTML comments
by perlfan (Parson) on Jan 04, 2012 at 14:55 UTC
    Perhaps you need to take this as an opportunity to create a more general set of SVG templates. I am assuming you have programmatic elements in the template. So your only choice is to exercise the template using HTML::Template and rendering a set of SVG files unencumbered with programming constructs or place holders. Then, edit them as you wish. Save this general set of templates somewhere safe, then make a copy of the set and "templatize" them. I'd recommend not using any constructs other than the TMPL_VARs. This way, in the future, updating the SVG is as simple as editing the source templates and regenerating the templates from there.