.mg Template files¶
.mg files are the base level files for Margarita. They contain your prompts and can be converted to plain Markdown on their own or can be used in .mgx files directly.
Example .mg file¶
<<
Hello, ${name}!
>>
Provide context¶
Add JSON either inline or in a file greeting.json:
{"name": "Batman"}
Render¶
Render the template with the CLI:
margarita render greeting.mg -f greeting.json
Rendered result¶
Using the template and context above the output will be:
Hello, Batman!
Alternate options¶
- Pass context as a JSON string:
-c '{"name": "Bob"}' - Render a directory of
.mgfiles:margarita render templates/ -o output/ - Inspect template metadata before rendering:
margarita render template.mg --show-metadata
Tip: When rendering a single file, MARGARITA will auto-detect a same-name
.jsonfile (e.g.greeting.json) if no context is supplied.