DownloadDOCX Template Structure Guide
Since DOCX files are binary, you need to create the template manually in Microsoft Word or LibreOffice.
How to Create a DOCX Template
-
Open Microsoft Word or LibreOffice Writer
-
Create a new document
-
Add the following placeholders (copy exactly as shown):
Template Content (Copy this into your Word document)
{{company_logo:image,width:400,ratio:16:9}}
===========================================
DOCUMENT GENERATOR TEST
===========================================
TEXT VARIABLES
--------------
Full Name: {{full_name:text}}
Email: {{email:string}}
Description: {{description:text}}
NUMBER VARIABLES
----------------
Age: {{age:number}} years old
Quantity: {{quantity:integer}} items
Price: ${{price:int}}
DATE VARIABLE
-------------
Created Date: {{created_date:date}}
BOOLEAN VARIABLE
----------------
Is Active: {{is_active:boolean}}
-------------------------------------------
Generated by DocumentGeneratorX
Test completed successfully!
Variable Reference
| Placeholder | Type | Example Value |
|------------|------|---------------|
| {{company_logo:image,width:400,ratio:16:9}} | Image with ratio | URL or file path |
| {{full_name:text}} | Text | "John Doe" |
| {{email:string}} | String | "john@example.com" |
| {{description:text}} | Text | "Lorem ipsum..." |
| {{age:number}} | Number | 28 |
| {{quantity:integer}} | Integer | 150 |
| {{price:int}} | Integer | 99 |
| {{created_date:date}} | Date | "2024-01-15" |
| {{is_active:boolean}} | Boolean | true/false |
Save the Template
-
Save the document as `sample.docx`
-
Place it in your Laravel storage: `storage/templates/sample.docx`
Usage in Code
use Hp\Documentgeneratorx\Facades\DocumentGenerator;
$docxPath = DocumentGenerator::template(storage_path('templates/sample.docx'))
->variables([
'company_logo' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/7/77/Google_Images_2015_logo.svg/1280px-Google_Images_2015_logo.svg.png',
'full_name' => 'John Doe',
'email' => 'john@example.com',
'description' => 'Test document generated with all variable types.',
'age' => 28,
'quantity' => 150,
'price' => 99,
'created_date' => now()->format('Y-m-d'),
'is_active' => true,
])
->format('docx')
->generate();
|