senny / sablon

Ruby Document Template Processor based on docx templates and Mail Merge fields.
MIT License
443 stars 126 forks source link

Insert Templates into one another #177

Open muhammadaliawan opened 2 years ago

muhammadaliawan commented 2 years ago

Is there a way to let Sablon insert a template into another template?

This would be helpful in a scenario in which a group of templates require the same content with exact formattings etc.

What I am thinking is that we simply give the S3 url of a template(the template which is going to be inserted into another template is already uploaded on AWS S3 bucket) to Sablon object and it fetches that template from S3 and places its content in the resultant template.

stadelmanma commented 2 years ago

Hi @muhammadaliawan I attempted to implement this a few years ago. It turned out to be very difficult because certain components of word documents exist in different places (e.g. lists, images, styles, to name a few). Since we were operating in a Ruby on Rails app, I chose to take advantage of its HTML rendering system instead and spread my complex reports across several HTML template partials. Then I used the ERB templating machinery to handle creating a final HTML blob to insert into the template.

If you really want to go this route you could accomplish something similar by extracting the relevant XML nodes from your “template document” and then using WordML content insertion.

muhammadaliawan commented 2 years ago

Okay, I will look into it. Thanks.