- Candidate Overview and Analysis Criteria
- 1. Classic MODX Parser (modParser): The Basic Tool
- Recommendations
- 2. Fenom (via pdoTools): the de facto standard in the MODX community
- Recommendations
- 3. Twig: An Industry Standard with a Barrier to Entry
- Recommendations
- 4. Smarty: A Legacy Solution
- Recommendations
- Comparative Analysis
- Conclusion and Recommendations
Candidate Overview and Analysis Criteria
In the context of MODX 3, four main templating approaches are considered:
- The Classic MODX Parser: is a built-in mechanism using the
[[...]]syntax. - Fenom: is integrated via the
pdoToolsadd-on and is the de facto community standard. - Twig: is an industry standard used by major frameworks (Symfony, Drupal), but with integration challenges in MODX 3.
- Smarty: is a historical engine used in some legacy MODX components.
Comparison criteria include: compatibility with MODX 3, architecture (compilation/iteration), DX (developer friendliness), and performance.
1. Classic MODX Parser (modParser): The Basic Tool
The classic MODX parser is the foundation for processing templates, chunks, and snippets, as it is built into the system core. It operates using recursive parsing, which means iterating through the content until all nested elements are fully processed. It uses square bracket syntax:
- Resource fields:
[[*tags]]or[[*pagetitle]] - Chunks (ready-made HTML blocks):
[[$header]]. - Snippets (PHP scripts):
[[snippet]]. - Placeholders:
[[+id]].
To execute dynamic logic and set values using snippets, a call to a non-cacheable placeholder is used, for example: [[! Profile]] Hello, [[! +username]].
Pros and cons of modParser
Recommendations
Use the classic parser only for simple projects, such as business card websites or other small sites with basic logic. It’s not suitable for complex solutions due to its syntactic clutter, difficulty debugging, the inability to use pure PHP code in templates, and the potential risk of instability associated with deep recursion.
2. Fenom (via pdoTools): the de facto standard in the MODX community
Fenom is a lightweight, fast, and flexible templating engine integrated via the pdoTools package. It converts templates into optimized PHP code, which is then cached and executed in a single pass.
pdoTools, in turn, is the cornerstone of modern MODX development, replacing many deprecated components such asgetResources,Wayfinder, andgetPage, offering optimized access to the database directly without using xPDO objects for resources. This ensures high speed and flexibility when working with data collections.
Fenom uses a concise syntax that significantly improves on cumbersome MODX tags, especially when working with control structures. The secure {$_modx} variable is used to access MODX objects, system settings, and resources.
| MODX (Classic) | Fenom (pdoTools) | Purpose |
| [[*pagetitle]] | {$_modx->resource.pagetitle} | Resource Field |
| [[%lexicon]] | {$_modx->lexicon(‘lexicon’)} | Output Lexicon |
| [[~15]] | {$_modx->makeUrl(15)} | Generate link |
| [[++system_setting]] | {$_modx->config.system_setting} | System setting |
[[+id:default=test]] |
{$id?: ‘test’} | Set value by default |
[[+id:is=“:then=`test`:else=`[[+pagetitle]]`]] |
{$id == ”? ‘test’ : $pagetitle} | Conditional Output |
One of the main advantages of Fenom is the ability to use control structures (loops, conditional logic) directly in chunks.
Example of complex structure output (MIGX): Fenom makes it easy to decode JSON data from TV fields and iterate over them:
{set $rows = json_decode($_modx->resource.tv_images, true)}
{foreach $rows as $row}
<img src="{$row.image}" alt="">
{/foreach}
Example of using modifiers. Modifiers are applied using the pipe operator (|). Fenom supports both its own built-in modifiers and those built into MODX. Example:
{$_modx->resource.publishedon | date_format:"%d-%m-%Y %H:%M:%S"}
{$_modx->resource.pagetitle | limit : '3' | lowercase}
Advantages and disadvantages of Fenom
{} may conflict with CSS/JS, requiring the use of the {ignore} tag. Alternatively, you should include a space before and after the curly brace.Recommendations
Fenom is the primary choice for most medium-complexity projects. It’s ideal for corporate websites, blogs, and catalogs.
To integrate Fenom into MODX:
- Install pdoTools via the MODX package manager (modstore.pro or a local repository).
- In system settings, enable
pdotools_fenom_parserto process templates and pages. - Configure
pdotools_fenom_defaultto process chunks. - Use Fenom syntax in templates and chunks, for example:
{if $_modx->resource.template == 1} <h1>{$_modx->resource.pagetitle}</h1> {/if} - To avoid conflicts with JS/CSS, use the
{ignore}tag:<style> {ignore} body { font-size: 16px; } {/ignore} </style>If you see a white screen instead of a page, these are parsing errors due to incorrect syntax or conflicts with curly braces. Solution: Check the logs and wrap the problematic code in
{ignore}.
3. Twig: An Industry Standard with a Barrier to Entry
Twig is a powerful, secure templating engine used in such giants as Symfony and Drupal. It offers clean syntax ({{ resource.pagetitle }}, {% for item in items %}...{% endfor %}), template inheritance, and a sandbox mode for safe code execution.
Usage example:
{% if resource.id == 1 %}
<h1>Welcome to {{ resource.pagetitle }}</h1>
{% endif %}
Additionally, Twig has a rich library of extensions, such as twig/extra-bundle, which provides access to additional features, including inline CSS processing (CSSinliner), internationalization (Intl), and Markdown processing.
Despite Twig’s superiority, its widespread use as the primary templating engine for the MODX 3 frontend is seriously hampered. Older extensions, such as modxTwig and phpTemplates, which previously provided integration, are now incompatible with MODX 3.
Currently, there is no current, actively maintained framework that would ensure seamless and consistent Twig operation as the primary templating engine for all MODX 3 templates and chunks. This forces developers to use Twig either in niche scenarios (such as the Commerce or Fred modules) or to create their own complex wrappers. The lack of a standardized frontend solution for MODX 3 prevents Twig from becoming a viable alternative to Fenom for mass development.
Pros and cons of Twig
Recommendations
Twig is suitable for complex projects where security and integration with external frameworks are important. However, significant customization is required for full use.
4. Smarty: A Legacy Solution
Smarty is one of the oldest PHP templating engines, focused on strict separation of PHP code from presentation.
Despite its capabilities, Smarty is not a viable choice for new MODX 3 projects. Extra modxSmarty (version 1.0.3-beta) was released on December 28, 2012. The extremely long time since its last release and the lack of active support in the PHP 8.x and MODX 3 era make this integration obsolete.
Advantages and disadvantages of Smarty
Recommendations
Use Smarty only to support legacy projects. It is not recommended for new developments.
Comparative Analysis
To simplify your decision-making, we’ve summarized the key features in a single table.
| Feature | Classic MODX | Fenom (pdoTools) | Twig | Smarty (Legacy) |
|---|---|---|---|---|
| Parsing Engine | Recursive | Compile to PHP | Compile to PHP | Compile to PHP |
| Compatibility with MODX 3 (Extra) | Built-in | Built-in (pdoTools) | No current/end-to-end Extra | Integration is outdated (2012) |
| Performance | Medium/Low | High | High | High |
| Up-to-date PHP 8.1+ | Yes | Yes | Yes (Twig 3.x) | Yes (Smarty 5.x) |
| Syntax / Readability | Low | High | High | Medium |
| Functionality | Limited | High | High | High |
| Template Inheritance | No | No (composition) | Yes | Yes |
| Security (Sandbox) | No | Limited | Yes | Yes |
| Setup Difficulty | Low | Medium | High | High |
| Community / Support | Wide | Wide (MODX) | Wide (outside MODX) | Limited |
Conclusion and Recommendations
The evolution of MODX 3 requires developers to stay current. Choosing a templating engine is a decision that impacts the performance, security, and maintainability of your project in the long term.
- For all new projects: use Fenom (pdoTools). It’s the fastest, most stable, and well-integrated option. It solves the fundamental problems of the classic parser and provides all the necessary tools for effective front-end development. Its community and support make it the safest choice.
- For complex enterprise solutions: consider Twig. If your project requires the highest level of security (sandboxing), a complex template hierarchy, or tight integration with external frameworks, and you have the resources for custom integration and support, Twig is your choice. However, be prepared for additional effort.
- For simple tasks: the classic parser is still alive. For small, simple sites without complex display logic, the built-in parser may be sufficient. But be aware of its architectural limitations.
- Avoid Smarty in new development. Choosing Smarty today is a conscious decision to incur technical debt.
Bottom line: Don’t be afraid to change. Install pdoTools, learn Fenom syntax, and you’ll not only experience a performance boost, but also discover that development has become more predictable and your code cleaner and easier to maintain. MODX 3 is ready for modern challenges, and your choice of templating engine is the key to unlocking its full potential.







