-
Notifications
You must be signed in to change notification settings - Fork 18
Enhance Handlebars example with multi-file template support and professional HTML output #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
4
commits into
master
Choose a base branch
from
copilot/fix-146
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
83f51dc
Initial plan
Copilot b3ceaf0
Enhance Handlebars example with multi-file templates and comprehensivβ¦
Copilot 22c0f2b
Fix critical bugs and improve code quality in Handlebars example
Copilot 671d361
Remove unused variables to clean up AL code
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Handlebars Multi-File Template Example | ||
|
|
||
| This example demonstrates how to use Handlebars with multiple template files to create a complete HTML document. The example shows a practical approach to organizing templates for better maintainability and reusability. | ||
|
|
||
| ## Template Structure | ||
|
|
||
| The example uses a multi-file template approach with the following structure: | ||
|
|
||
| ### 1. Main Layout Template (`templates/layout.html`) | ||
| - Contains the base HTML structure | ||
| - Includes CSS styling | ||
| - References other templates using partials (`{{> template-name}}`) | ||
|
|
||
| ### 2. Header Template (`templates/header.html`) | ||
| - Company information and branding | ||
| - Order confirmation header | ||
| - Customer and date information | ||
|
|
||
| ### 3. Order Details Template (`templates/order-details.html`) | ||
| - Order number and line items | ||
| - Detailed product information with quantities and prices | ||
| - Total amount calculation | ||
|
|
||
| ### 4. Footer Template (`templates/footer.html`) | ||
| - Company contact information | ||
| - Thank you message | ||
| - Document generation notice | ||
|
|
||
| ## Implementation Details | ||
|
|
||
| The AL codeunit `HandlebarsTest` demonstrates three different approaches: | ||
|
|
||
| ### 1. Single Template (`RenderFromSingleTemplate`) | ||
| Basic template rendering with all content in one template string. | ||
|
|
||
| ### 2. Simple Partials (`RenderWithPartials`) | ||
| Uses Handlebars partials to separate header and line templates. | ||
|
|
||
| ### 3. Multi-File Template (`RenderFromMultiFileTemplate`) | ||
| **NEW**: Demonstrates a complete multi-file template approach: | ||
| - Loads multiple template files as partials | ||
| - Combines them into a complete HTML document | ||
| - Uses enhanced data payload with company information | ||
| - Produces a professional-looking order confirmation document | ||
|
|
||
| ## Key Features | ||
|
|
||
| - **Separation of Concerns**: Each template file handles a specific part of the document | ||
| - **Reusability**: Templates can be reused across different document types | ||
| - **Maintainability**: Easy to update individual sections without affecting others | ||
| - **Professional Output**: Generates complete HTML documents with proper styling | ||
| - **Rich Data Binding**: Demonstrates complex data structures with nested objects and arrays | ||
|
|
||
| ## Usage | ||
|
|
||
| The `RenderFromMultiFileTemplate` test method shows how to: | ||
|
|
||
| 1. Initialize the Handlebars renderer | ||
| 2. Load multiple template files as partials | ||
| 3. Set the main layout template | ||
| 4. Create a comprehensive data payload | ||
| 5. Render the complete HTML document | ||
| 6. Validate the output | ||
|
|
||
| ## Data Structure | ||
|
|
||
| The enhanced payload includes: | ||
| - **Document Properties**: Title, date | ||
| - **Company Information**: Name, address, phone | ||
| - **Order Information**: Number, customer, date | ||
| - **Line Items**: Product details with pricing | ||
| - **Calculations**: Total amounts | ||
|
|
||
| This example provides a foundation for creating complex, multi-file template systems in Business Central using the EOS Handlebars integration. |
56 changes: 56 additions & 0 deletions
56
EX004.EosAdminLib/Handlebars/templates/example-output.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Order Confirmation - SO12345</title> | ||
| <style> | ||
| body { font-family: Arial, sans-serif; margin: 20px; } | ||
| .header { background-color: #f8f9fa; padding: 20px; border-radius: 5px; margin-bottom: 20px; } | ||
| .content { margin: 20px 0; } | ||
| .footer { background-color: #e9ecef; padding: 15px; border-radius: 5px; margin-top: 20px; text-align: center; } | ||
| .order-lines { list-style-type: none; padding: 0; } | ||
| .order-line { background-color: #f8f9fa; margin: 5px 0; padding: 10px; border-radius: 3px; } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <!-- Header Template Content --> | ||
| <div class="header"> | ||
| <h1>ACME Corporation</h1> | ||
| <h2>Order Confirmation</h2> | ||
| <p><strong>Customer:</strong> John Doe</p> | ||
| <p><strong>Date:</strong> 2024-01-15</p> | ||
| </div> | ||
|
|
||
| <div class="content"> | ||
| <!-- Order Details Template Content --> | ||
| <div class="order-details"> | ||
| <h3>Order #SO12345</h3> | ||
| <p>Thank you for your order! Below are the details:</p> | ||
|
|
||
| <h4>Order Lines:</h4> | ||
| <ul class="order-lines"> | ||
| <li class="order-line"> | ||
| <strong>ITEM001</strong> - Premium Widget | ||
| <br>Quantity: 2 | Unit Price: $50.00 | Amount: $100.00 | ||
| </li> | ||
| <li class="order-line"> | ||
| <strong>ITEM002</strong> - Standard Widget | ||
| <br>Quantity: 5 | Unit Price: $25.00 | Amount: $125.00 | ||
| </li> | ||
| </ul> | ||
|
|
||
| <div style="text-align: right; margin-top: 20px;"> | ||
| <p><strong>Total Amount: $225.00</strong></p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <!-- Footer Template Content --> | ||
| <div class="footer"> | ||
| <p>Thank you for your business!</p> | ||
| <p>ACME Corporation | 123 Business St, City | (555) 123-4567</p> | ||
| <p><small>This is an automatically generated document.</small></p> | ||
| </div> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <div class="footer"> | ||
| <p>Thank you for your business!</p> | ||
| <p>{{CompanyName}} | {{CompanyAddress}} | {{CompanyPhone}}</p> | ||
| <p><small>This is an automatically generated document.</small></p> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <div class="header"> | ||
| <h1>{{CompanyName}}</h1> | ||
| <h2>Order Confirmation</h2> | ||
| <p><strong>Customer:</strong> {{CustomerName}}</p> | ||
| <p><strong>Date:</strong> {{OrderDate}}</p> | ||
| </div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
give better comment