We use cookies to make your viewing experience better. By accepting you consent, you agree to our Cookie policy

Accept
Improve your Craft CMS skills

What Framework Does Craft CMS Use?

10 min read
What Framework Does Craft CMS Use

Craft CMS has quickly become a top choice for developers building custom digital experiences. But with its flexibility, what exactly provides Craft's underlying framework foundation? This piece digs into the modern PHP, Twig, and Yii frameworks powering Craft to deliver customized, scalable sites. Read on to understand the core technologies enabling Craft CMS's extensible approach.

Craft CMS is built on top of the modern PHP 7 programming language, the Twig templating engine for frontend markup, and the Yii2 PHP framework for the underlying MVC architecture. This provides a fast, secure, and extensible foundation.

Key Features and Benefits of Craft CMS

Flexible and Customizable Content Modeling

One of the standout features of Craft CMS is its extraordinarily flexible content modelling capabilities. Unlike rigid off-the-shelf CMS solutions, Craft provides developers with complete control to create bespoke content structures tailored to their exact needs.

With Craft's Sections, Fields, Categories, Tags, Matrix blocks and other elements, developers can model complex content relationships and data structures. For example, you could create a matrix field linking articles to related videos and transcripts, or build a staff directory with custom fields for each employee's photo, bio, and contact details. The possibilities are endless.

Compared to systems like WordPress that lock you into set post types and fields, Craft's flexibility is a game-changer. No more trying to pound square pegs into round holes to make a CMS fit your use case. With Craft, you can craft any content model you can imagine.

Developer-Focused Extensibility with Plugins and APIs

Another area where Craft shines is its deep extensibility for developers. Craft embraces plugins and customization as core principles.

Developers can tap into a rich Craft CMS plugin ecosystem to extend Craft's admin and frontend functionality. Want ecommerce features? A custom form builder? Enhanced search? There's likely a plugin for that. The Craft Plugin Store offers hundreds of free and paid plugins to accelerate development.

Craft also provides a robust set of APIs for integrating with other systems and building custom functionality. JSON APIs enable headless CMS integrations, while Craft's templating, plugins and query APIs let you customize just about anything.

For large enterprise implementations, Craft's extensibility means it can scale up to the most complex needs. You're never boxed in by the out-of-the-box system.

Modern Templating with Twig

Craft leverages the flexible Twig templating language to provide complete control over frontend markup and presentation logic.

Twig's template inheritance enables developers to build robust, reusable base templates with blocks that can be overridden. Macro tags make it easy to create reusable snippets of code.

The template separation from content means developers can build auto-scaling responsive layouts and themes that stay decoupled from content edits. And non-technical content editors never have to touch code or understand Twig - they just see an intuitive editing interface.

For developers who value clean semantics and logicless templates, Twig is a breath of fresh air compared to cluttered PHP templating. The {% block %} tags and .twig extensions make templates easy to scan and understand.

Overall, Twig is the ideal templating engine for Craft, enabling complete frontend customization in a developer-friendly way.

Craft CMS packs a one-two punch of flexible content modelling and deep customization that sets it apart from other solutions. The developer-focused extensibility lets it scale up for complex sites, while the Twig templating empowers frontend developers. For projects where a tailored CMS is needed, Craft truly lets you "craft your content".

https://craft-cmshub-staging.c...The Twig Templating Engine

Twig Overview and Features

Twig is an open source PHP templating engine that has gained widespread popularity as a robust alternative to regular PHP templates. One of the standout capabilities Twig provides is template inheritance - the ability to define nested layout blocks in parent templates that can be overridden by child templates. This enables much better code organization through reuse of common markup in the parent template. Twig also provides macros, which are reusable chunks of code that can be included anywhere, similar to functions in programming languages. Macros are excellent for eliminating duplicate code.

Beyond template inheritance and macros, Twig offers filters for modifying variables, functions for accomplishing common tasks, sandbox mode for improved security, and fast compilation to optimized PHP. Twig compiles templates down to plain PHP code, which improves performance compared to uncompiled PHP templates. The sandbox mode is also beneficial, as it prevents direct execution of PHP code in templates, avoiding common vulnerabilities found in raw PHP templates.

Overall, Twig provides a much cleaner and more readable syntax compared to regular PHP templates. Its logicless template design enforces a better separation of concerns between presentational markup and business logic. For these reasons, Twig solves many common pain points found in traditional PHP templating.

Benefits of Twig Templating

The cleaner syntax of Twig, with its {% bracket %} tags, is far more readable and maintainable than complex PHP logic embedded in templates. Twig is also more secure, as its sandbox mode restricts direct execution of PHP code. Additionally, the compilation of Twig down to optimized PHP leads to faster performance than uncompiled PHP templates.

Twig strongly embraces the DRY principle, with features like macros, and template inheritance, and includes to reduce code duplication. The separation of logic from presentation fosters improved designer-developer workflows and long-term maintainability.

As a mature open source project, Twig offers thousands of pre-built extensions and abundant documentation and community support. The extensibility provided through custom functions, filters, and tags means Twig can be tailored to any project's needs.

By incorporating best practices and concepts from languages like Python's Django framework, Twig brings professional-grade templating capabilities to PHP projects. The multitude of advantages make Twig a wise choice for modern PHP development.

Twig Integration in Craft CMS

Craft CMS heavily utilizes Twig for its entire front-end templating and presentation layer. Twig powers the .twig templates that define the markup and output of the front-end.

Developers can leverage all of Twig's capabilities like inheritance, macros, sandboxing, and logicless syntax when building Craft themes. For example, a base _layout.twig template can contain reusable header, footer, and content blocks for child templates to extend. Macros are great for modular snippets like _macros/forms.twig that handles form markup.

The separation provided by Twig means content editors never have to work directly with code or understand Twig syntax. The front-end remains fully customizable for developers, while editors focus exclusively on content.

For a developer-centric CMS like Craft, Twig is the ideal templating companion. It facilitates fully customized front-end experiences and neatly separates presentation logic from content authoring.

The Yii2 Framework Foundation

Overview of the Yii2 PHP Framework

Yii2 is a modern open source PHP framework that follows the model-view-controller architectural pattern to provide a structured foundation for building web applications. One of Yii2's hallmarks is its emphasis on modular organization - apps can be divided into reusable modules with a clear separation of code responsibilities. This promotes the development of maintainable and decentralized code. Yii2 also has sophisticated built-in caching capabilities for optimizing performance by caching things like database queries, API responses, and fragments of rendered views.

On the security front, Yii2 equips developers with tools like input validation, SQL injection prevention, cross-site scripting filtering and more to help build apps resilient against common vulnerabilities. The framework simplifies the creation of RESTful APIs with its support for REST methodology and JSON response formats. Unit testing is tightly integrated into the framework's structure through features like fixtures to encourage robust test coverage. And Yii2 offers deep customizability through its vast extension library of free and paid add-ons.

Compared to alternatives, Yii2 places strong emphasis on following object-oriented best practices and structured MVC patterns to facilitate code that is DRY, maintainable, and well-organized. This makes Yii2 well-suited for large, complex application development.

Key Benefits of Using Yii2

The modularity enabled by Yii2's components, modules, and submodules allows code responsibilities to be divided up in a reusable way. This decentralization provides long-term maintainability advantages. Yii2 also delivers excellent baseline performance that can rival other PHP frameworks like Laravel, thanks to its integrated caching and optimizations.

Robust security tools like SQL injection prevention, cross-site scripting filters, and cross-site request forgery protection help developers build apps secured against common vulnerabilities. Yii2 promotes high code quality by encouraging namespaces, interfaces, strict MVC, and testing - all best practices for clean and maintainable code.

For API development, Yii2 simplifies building JSON APIs that follow REST principles and provides tools for customizing and optimizing responses. And Yii2's interoperability with commonly used frameworks like Symfony and testing tools like PHPUnit increases flexibility.

Yii2 Integration in Craft CMS

Craft CMS is architected directly on top of Yii2, which provides its underlying MVC framework foundation. This allows Craft to offer a flexible platform for developing both first-party and third-party plugins.

Plugins in Craft can be organized as Yii2 modules with dedicated controllers, models, views and other app components. This modular architecture allows complex add-ons to be constructed while enforcing a clean separation of code responsibilities.

By building on Yii2, Craft also inherits strengths like security protections, code quality encouragement through testing, and high performance. The tight integration enables plugins to leverage Yii2's capabilities.

Overall, Yii2 provides Craft with a robust and flexible PHP foundation ideal for a modular CMS architecture. It empowers Craft to offer deep extendability through its plugin ecosystem.

Modern PHP 7 Programming

PHP 7 Overview and Capabilities

PHP 7 represents a major modernization of the PHP language with many new capabilities compared to outdated PHP 5.x versions. Some key improvements in PHP 7 include:

  • Dramatic performance boost - Benchmarks show PHP 7 can execute twice as fast compared to the previous PHP 5.6 version, thanks to an upgraded Zend engine and opcode cache.

  • Stronger type declarations - PHP 7 adds new scalar type declarations like bool, int, float, and stricter type handling to catch errors.

  • Consistency fixes - Irregularities in PHP 5 parsed as errors are standardized in PHP 7 for more consistent behaviour.

  • Return type declarations - Functions can now declare the data type they return.

  • Null coalescing operator - The new ?? operator provides a shorthand ternary for null checks.

  • New data structures - PHP 7 introduces the ArrayObject class, adds new intdiv() math functions and more.

By adopting modern programming best practices, PHP 7 represents a huge leap forward for the language. The performance gains, stronger typing, and consistency fixes make PHP 7 the ideal choice for new development vs outdated PHP 5.x.

Integration of PHP in Craft CMS

Craft CMS is implemented in object-oriented PHP and requires the modern PHP 7 engine to run. This allows Craft to utilize all the capabilities of PHP 7 like strict typing for security and performance optimizations through just-in-time compilation and the opcode cache.

Craft uses Composer to manage PHP dependencies, making it easy to integrate best-of-breed PHP libraries into projects. The Twig templating engine separates front-end presentation concerns from the backend PHP business logic.

This clean separation of PHP code and Twig templates provides the best of both worlds - fast PHP 7 powering the backend logic, while Twig handles presentational markup for the front-end UI.

Developing Custom PHP Logic

Within Craft CMS, developers can integrate custom PHP code to execute backend application logic beyond what comes out of the box.

For example, custom PHP controllers can be created to expose JSON APIs and endpoints. PHP models enable interaction with external services and databases. Form handlers process submissions and execute logic.

All of this custom backend PHP can integrate seamlessly into Craft's existing structures. The code executes with the full power of a modern PHP 7 engine, unlike outdated platforms running on legacy PHP 5.

For developers who enjoy working in object-oriented PHP, Craft provides endless freedom to incorporate custom PHP business logic, backends, services, and more. And it brings the end-to-end stack up to modern standards with PHP 7 and Composer.

Customizable Content Modeling

Sections, Fields and Content Entries

A core strength of Craft CMS is its flexible content modelling capabilities. Content structures are built up from Sections, which act as containers for Entries made up of various Fields.

Developers can define any number of Sections to represent different content types like News, Events, Pages etc. Within each Section, specific Fields are configured that shape the structure of Entries. For example, an "Event" Section could contain Fields like "Title", "Date", "Location", "Description", "Featured Image" and so on.

The Field types available in Craft include common ones like Plain Text, Rich Text, Dropdowns, Checkboxes and many more. Each Field can be customized with parameters like if it's required, validation rules, and UI presentation settings. This enables completely tailored content modelling.

Overall, Sections, Entries, and Fields provide the building blocks for modelling any kind of content structure imaginable in Craft.

Matrix Fields for Complex Modeling

While standard Fields work for simple data, Craft's Matrix field enables complex hierarchical and relationship modelling far beyond what you could do in a traditional relational database.

Matrix consists of Block Types that define a repeating set of fields, and actual Matrix blocks with populated content based on those field schemas. For example, a Movie Page Section could have a Matrix field with Review, Cast, and Trailer Blocks.

This allows highly structured and related content to be authored in one place. Fields can then be nested within other Fields in matrices of matrices. Craft's Matrix field handles the intricate storage and querying of all this complex related data under the hood.

Matrix provides endless possibilities for deeply relating content modelling.

Custom Field Types

In addition to Craft's built-in fields, there is a vast ecosystem of first-party and third-party custom Field types that enable tailored modelling for specific use cases.

For example, the Table and SuperTable fields provide spreadsheet-like interfaces for managing tabular data like product catalogs or staff directories. Neo provides tailored fields for optimized Matrix modelling. And many other custom fields exist for needs like ecommerce, real estate, job postings, and more.

Craft's field API makes it simple for plugin developers to build their own field types as well. This extensibility enables truly customized content modelling capabilities for any industry or vertical.

With the flexibility of Sections and Fields, the power of Matrix, and an ecosystem of custom field types, Craft provides unrivalled modelling capabilities for complex content domains.

Extensibility and Customization

Custom Fields

One of Craft's most powerful capabilities is letting developers create completely custom field types for specialized content modelling needs.

The field API enables building fields with customized inputs, validation, templates for front-end display, configurable settings pages, and more. For example, a Video field could allow embedding videos from YouTube, Vimeo etc. or uploading files to show in the front-end. An Events Calendar field could enable selecting dates and viewing an interactive calendar.

Developers can distribute custom fields as plugins on the Craft Plugin Store, providing tailored modelling for industries like real estate, jobs, ecommerce, and niche verticals. Custom fields are also a key capability that makes headless Craft CMS integration thrive.

Overall, custom fields enable virtually endless possibilities for modelling all kinds of structured content beyond what comes built into Craft out of the box.

Custom Modules and Plugins

Craft enables developers to extend their backend admin and front-end functionality by building custom modules and plugins.

For the control panel, modules can include custom templates, controllers, services, reports and more. This allows related tools to be grouped into dedicated sections. On the front-end, plugins can integrate templates, variables, APIs and other features to enable new presentation capabilities.

Popular use cases include ecommerce, form building, social integrations, SEO enhancements, performance optimizations and countless more focused enhancements. With modular code following best practices, plugins enable customizing Craft for specialized sites.

The Craft Plugin Store offers hundreds of free and premium extensions to accelerate development. And the flexibility makes Craft CMS an ideal platform for agency-focused developers.

APIs and Headless Mode

Craft also offers robust APIs to enable "headless" CMS architectures decoupled from front-end delivery.

Rather than a monolithic structure, headless setups allow Craft to manage content while other frameworks like React, Vue or Angular drive the front-end. Craft's GraphQL and JSON APIs integrate seamlessly with JavaScript apps.

Pros of headless Craft include the flexibility to use any front-end stack, real-time previews from any device, and front-end performance gains. The tradeoff is some loss of tight coupling between templates and content.

Either way, the availability of APIs and decoupled architecture options provides flexibility compared to traditional, monolithic CMS platforms.

Overall, custom fields, plugins, and headless integrations enable developers to deeply customize Craft CMS for any project's needs. This vast extensibility makes Craft at home in a wide variety of development workflows.

Built for Modern Web Development

Optimized Workflows

A key focus with Craft CMS is optimizing the critical workflows and tools involved in modern web development. Craft integrates tightly with tools like NPM, Webpack, Vue.js, Git, and Composer to remove friction from the dev process.

For front-end asset management, Craft's Control Panel UI is bundled via NPM and Webpack for smooth integration into JavaScript-driven stacks. Templating happens via Vue components for enhanced reactivity. And tools like Git and Composer are leveraged for efficient version control and dependency management.

By mirroring cutting-edge workflows, Craft removes the impedance mismatch often found when integrating traditional CMS platforms into modern tech stacks. Whether building websites or web apps, Craft's optimized toolchain integrates seamlessly.

Live Preview Editor

Craft also simplifies content authoring through its user-friendly control panel and live preview capabilities.

The intuitive drag and drop interface with inline editing makes building pages visually intuitive. Fields provide rich text, images, videos and other blocks tailored for web content. The front-end live preview editor updates changes in real-time so content authors can see edits as they build out pages.

The streamlined content creation and editing experience provided by Craft removes friction and bottlenecks for organizations managing many editorial users and high volumes of content.

Native Git and Docker Support

To simplify maintaining site projects over time, Craft offers native integration with essential DevOps tools like Git and Docker.

Git version control can be managed directly through the control panel UI or CLI, enabling proper tracking of content changes. And Craft's Docker containers allow effortlessly deploying staging and production environments using standardized containers.

With built-in support for these critical technologies, Craft removes headaches related to configuring disjointed workflows, allowing teams to focus their energy on building digital experiences rather than wrestling with complexity.

Overall, by holistically embracing modern web development practices from tooling to workflows, Craft CMS removes friction and helps organizations work faster and smarter.

Shape April 2022 HR 202
Andy Golpys
- Author

Andy has scaled multiple businesses and is a big believer in Craft CMS as a tool that benefits both Designer, Developer and Client. 

Share
Feedback
Show us some love
Email Us
We usually reply within 72 hours
Agency Directory
Submit your agency
Affiliate Partners
Let's chat