You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[The Template Engines We Support](#the-template-engines-we-support)
34
35
*[EJS](#ejs)
35
36
*[Markdown](#markdown)
@@ -562,9 +563,70 @@ Ecto has added in some helper functions for frontmatter in markdown files. Front
562
563
563
564
* `.hasFrontMatter(source: string): boolean` - This function checks if the markdown file has frontmatter. It takes in a string and returns a boolean value.
564
565
* `.getFrontMatter(source: string): object` - This function gets the frontmatter from the markdown file. It takes in a string and returns an object.
565
-
* `setFrontMatter(source:string, data: Record<string, unknown>)` - This function sets the front matter even if it already exists and returns the full source with the new front matter.
566
+
* `setFrontMatter(source:string, data: Record<string, unknown>)` - This function sets the front matter even if it already exists and returns the full source with the new front matter.
566
567
* `.removeFrontMatter(source: string): string` - This function removes the frontmatter from the markdown file. It takes in a string and returns a string.
567
568
569
+
# Detect Template Engine
570
+
571
+
Ecto provides a `detectEngine` method that can automatically detect the template engine from a template string by analyzing its syntax patterns. This is useful when you receive template content but don't know which engine it uses.
572
+
573
+
## detectEngine(source: string): string
574
+
575
+
The `detectEngine` method analyzes the template syntax and returns the detected engine name. If no specific template syntax is found, it returns the configured default engine.
| source | string | The template source string to analyze |
580
+
581
+
**Returns:** The detected engine name ('ejs', 'markdown', 'pug', 'nunjucks', 'handlebars', 'liquid') or the default engine if no specific syntax is detected.
582
+
583
+
### Basic Usage
584
+
585
+
```javascript
586
+
constecto=newEcto();
587
+
588
+
// Detect EJS templates
589
+
constejsEngine=ecto.detectEngine('<%= name %>');
590
+
console.log(ejsEngine); // 'ejs'
591
+
592
+
// Detect Handlebars templates
593
+
consthbsEngine=ecto.detectEngine('{{name}}');
594
+
console.log(hbsEngine); // 'handlebars'
595
+
596
+
// Detect Markdown
597
+
constmdEngine=ecto.detectEngine('# Hello World\n\nThis is markdown');
Note: For ambiguous syntax (like simple `{{ }}` which could be Handlebars, Mustache, or Liquid), the method makes intelligent decisions based on additional context clues in the template.
629
+
568
630
# Caching on Rendering
569
631
570
632
Ecto has a built-in caching mechanism that is `disabled by default` that allows you to cache the rendered output of templates. This is useful for improving performance and reducing the number of times a template needs to be rendered. There are currently two caching engines available: `MemoryCache` and `FileCache`.
0 commit comments