What is CI4's template parser?
Answer
CodeIgniter 4's View Parser is a simple template system that replaces pseudo-variables with data without requiring full PHP execution. Load: $parser = service("parser"). Render: $parser->render("template", $data). Simple variables: {username} is replaced with the username value from the data array. Variable pairs (loops): {users}{name}{/users} iterates over the users array. Conditionals: {if $active}Active{/if} and {if $age > 18}Adult{else}Minor{/if}. Escaped output: pseudo-variables are automatically HTML-escaped. Comments: {# This is a comment #}. The View Parser is simpler than Twig or Blade — it is suitable for non-PHP developers maintaining templates, CMS content, or email templates. For powerful templating with filters, inheritance, and macros, integrate Twig via Composer. The parser has lower overhead than PHP-based templates.