# twig

Published articles for twig.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Going Global with Twig Globals in Craft CMS

DevFeed: [Going Global with Twig Globals in Craft CMS](<https://devfeed.tech/articles/going-global-with-twig-globals-in-craft-cms-31265.md>)

Original publisher: [Read original article](<https://nystudio107.com/blog/going-global-with-twig-globals-in-craft-cms>)

Author: andrew@nystudio107.com (Andrew Welch)

Published: 2024-09-02T18:25:00Z

Content type: tutorial

Language: en

Sources: [nystudio107 | Articles on modern web development.](<https://devfeed.tech/sources/nystudio107-articles-on-modern-web-development.md>)

Topics: [Content Management System](<https://devfeed.tech/topics/cms.md>), [Web](<https://devfeed.tech/topics/web.md>), [coding](<https://devfeed.tech/topics/coding.md>)

Tags: [added](<https://devfeed.tech/tags/added.md>), [article](<https://devfeed.tech/tags/article.md>), [challenges](<https://devfeed.tech/tags/challenges.md>), [cms](<https://devfeed.tech/tags/cms.md>), [collection](<https://devfeed.tech/tags/collection.md>), [craft](<https://devfeed.tech/tags/craft.md>), [global](<https://devfeed.tech/tags/global.md>), [globals](<https://devfeed.tech/tags/globals.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [insights](<https://devfeed.tech/tags/insights.md>), [learn](<https://devfeed.tech/tags/learn.md>), [leveraging](<https://devfeed.tech/tags/leveraging.md>), [simplify](<https://devfeed.tech/tags/simplify.md>), [templating](<https://devfeed.tech/tags/templating.md>), [twig](<https://devfeed.tech/tags/twig.md>), [variables](<https://devfeed.tech/tags/variables.md>)

### AI overview

This tutorial explains how variable scope works in Twig templates used by Craft CMS, including the challenges of making variables globally available. It discusses the trade-offs of global variables and how they can reduce component reusability and modularity, while noting that they can be appropriate in simpler websites.

### Source excerpt

Learn how to simplify some Twig templating challenges by leveraging the global variables & the _globals Collection added in Craft CMS 4.5

## Advanced String Manipulation in Twig with Craft CMS

DevFeed: [Advanced String Manipulation in Twig with Craft CMS](<https://devfeed.tech/articles/advanced-string-manipulation-in-twig-with-craft-cms-31304.md>)

Original publisher: [Read original article](<https://nystudio107.com/blog/string-manipulation-in-twig-with-craft-cms>)

Author: andrew@nystudio107.com (Andrew Welch)

Published: 2024-05-01T17:39:00Z

Content type: tutorial

Language: en

Sources: [nystudio107 | Articles on modern web development.](<https://devfeed.tech/sources/nystudio107-articles-on-modern-web-development.md>)

Topics: [Content Management System](<https://devfeed.tech/topics/cms.md>), [PHP](<https://devfeed.tech/topics/php.md>), [Library](<https://devfeed.tech/topics/library.md>), [Code](<https://devfeed.tech/topics/code.md>), [phpstorm](<https://devfeed.tech/topics/phpstorm.md>)

Tags: [advanced](<https://devfeed.tech/tags/advanced.md>), [craft](<https://devfeed.tech/tags/craft.md>), [hidden](<https://devfeed.tech/tags/hidden.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [insights](<https://devfeed.tech/tags/insights.md>), [learn](<https://devfeed.tech/tags/learn.md>), [manipulation](<https://devfeed.tech/tags/manipulation.md>), [plugins](<https://devfeed.tech/tags/plugins.md>), [powers](<https://devfeed.tech/tags/powers.md>), [required](<https://devfeed.tech/tags/required.md>), [string](<https://devfeed.tech/tags/string.md>), [twig](<https://devfeed.tech/tags/twig.md>), [unleash](<https://devfeed.tech/tags/unleash.md>)

### AI overview

This tutorial explains how to perform advanced string manipulation in Twig with Craft CMS without additional plugins. It shows how to access the bundled Stringy PHP library through Twig's create() function and demonstrates several Stringy functions.

### Source excerpt

Learn how to unleash hidden string manipulation powers in Twig with Craft CMS 5, no plugins required!

## Making Twig Macros Work Like Functions

DevFeed: [Making Twig Macros Work Like Functions](<https://devfeed.tech/articles/making-twig-macros-work-like-functions-31280.md>)

Original publisher: [Read original article](<https://nystudio107.com/blog/making-twig-macros-work-like-functions>)

Author: andrew@nystudio107.com (Andrew Welch)

Published: 2023-07-14T18:38:00Z

Content type: tutorial

Language: en

Sources: [nystudio107 | Articles on modern web development.](<https://devfeed.tech/sources/nystudio107-articles-on-modern-web-development.md>)

Topics: [Programming](<https://devfeed.tech/topics/programming.md>), [Development](<https://devfeed.tech/topics/development.md>), [reusable code](<https://devfeed.tech/topics/reusable-code.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [functions](<https://devfeed.tech/tags/functions.md>), [insights](<https://devfeed.tech/tags/insights.md>), [just](<https://devfeed.tech/tags/just.md>), [languages](<https://devfeed.tech/tags/languages.md>), [learn](<https://devfeed.tech/tags/learn.md>), [like](<https://devfeed.tech/tags/like.md>), [macros](<https://devfeed.tech/tags/macros.md>), [make](<https://devfeed.tech/tags/make.md>), [manipulate](<https://devfeed.tech/tags/manipulate.md>), [programming](<https://devfeed.tech/tags/programming.md>), [programming-languages](<https://devfeed.tech/tags/programming-languages.md>), [return](<https://devfeed.tech/tags/return.md>), [returning](<https://devfeed.tech/tags/returning.md>), [reusable-code](<https://devfeed.tech/tags/reusable-code.md>), [twig](<https://devfeed.tech/tags/twig.md>), [value](<https://devfeed.tech/tags/value.md>), [values](<https://devfeed.tech/tags/values.md>)

### AI overview

A tutorial on making Twig macros return values that can be manipulated like function results. It demonstrates a sales-calculation macro, whitespace control, and returning a value for further computations such as sales tax.

### Source excerpt

Learn how to make Twig macros return values you can manipulate, just like functions in other programming languages

## Searching Craft CMS Matrix Blocks

DevFeed: [Searching Craft CMS Matrix Blocks](<https://devfeed.tech/articles/searching-craft-cms-matrix-blocks-31293.md>)

Original publisher: [Read original article](<https://nystudio107.com/blog/searching-craft-cms-matrix-blocks>)

Author: andrew@nystudio107.com (Andrew Welch)

Published: 2021-11-26T05:00:00Z

Content type: tutorial

Language: en

Sources: [nystudio107 | Articles on modern web development.](<https://devfeed.tech/sources/nystudio107-articles-on-modern-web-development.md>)

Topics: [Query (disambiguation)](<https://devfeed.tech/topics/query.md>), [Content Management System](<https://devfeed.tech/topics/cms.md>)

Tags: [based](<https://devfeed.tech/tags/based.md>), [behavior](<https://devfeed.tech/tags/behavior.md>), [blocks](<https://devfeed.tech/tags/blocks.md>), [cms](<https://devfeed.tech/tags/cms.md>), [contain](<https://devfeed.tech/tags/contain.md>), [contents](<https://devfeed.tech/tags/contents.md>), [craft](<https://devfeed.tech/tags/craft.md>), [custom](<https://devfeed.tech/tags/custom.md>), [easily](<https://devfeed.tech/tags/easily.md>), [elements](<https://devfeed.tech/tags/elements.md>), [entries](<https://devfeed.tech/tags/entries.md>), [insights](<https://devfeed.tech/tags/insights.md>), [little](<https://devfeed.tech/tags/little.md>), [matrix](<https://devfeed.tech/tags/matrix.md>), [php](<https://devfeed.tech/tags/php.md>), [query](<https://devfeed.tech/tags/query.md>), [twig](<https://devfeed.tech/tags/twig.md>)

### AI overview

A tutorial on querying Craft CMS Entries by the content of their Matrix blocks. It explains how to find matching Matrix blocks, collect their owner IDs, and use those IDs to filter an Element query, including a generalized approach usable in Twig.

### Source excerpt

With a little custom Behavior, we can easily query for Elements such as Entries in Craft CMS based on the contents of the Matrix Blocks they contain

## An Effective Twig Base Templating Setup

DevFeed: [An Effective Twig Base Templating Setup](<https://devfeed.tech/articles/an-effective-twig-base-templating-setup-31241.md>)

Original publisher: [Read original article](<https://nystudio107.com/blog/an-effective-twig-base-templating-setup>)

Author: andrew@nystudio107.com (Andrew Welch)

Published: 2019-11-21T01:29:00Z

Content type: tutorial

Language: en

Sources: [nystudio107 | Articles on modern web development.](<https://devfeed.tech/sources/nystudio107-articles-on-modern-web-development.md>)

Topics: [Content Management System](<https://devfeed.tech/topics/cms.md>), [Template](<https://devfeed.tech/topics/template.md>), [Web Development](<https://devfeed.tech/topics/web-development.md>), [Development](<https://devfeed.tech/topics/development.md>), [Front end](<https://devfeed.tech/topics/frontend.md>)

Tags: [base](<https://devfeed.tech/tags/base.md>), [build](<https://devfeed.tech/tags/build.md>), [cms](<https://devfeed.tech/tags/cms.md>), [craft](<https://devfeed.tech/tags/craft.md>), [foundation](<https://devfeed.tech/tags/foundation.md>), [good](<https://devfeed.tech/tags/good.md>), [insights](<https://devfeed.tech/tags/insights.md>), [projects](<https://devfeed.tech/tags/projects.md>), [provides](<https://devfeed.tech/tags/provides.md>), [setup](<https://devfeed.tech/tags/setup.md>), [solid](<https://devfeed.tech/tags/solid.md>), [stable](<https://devfeed.tech/tags/stable.md>), [templates](<https://devfeed.tech/tags/templates.md>), [templating](<https://devfeed.tech/tags/templating.md>), [twig](<https://devfeed.tech/tags/twig.md>)

### AI overview

This tutorial presents a reusable Twig base templating setup for Craft CMS websites. It explains the role of Twig as a presentation layer and outlines desired capabilities, including reuse across projects, support for web pages and AJAX/XHR modals, core features with flexibility, and Google AMP pages when appropriate.

### Source excerpt

A good base templating setup for your Craft CMS Twig templates provides a stable, solid foundation on which to build your projects

## Auto-Complete Craft CMS 3 APIs in Twig with PhpStorm

DevFeed: [Auto-Complete Craft CMS 3 APIs in Twig with PhpStorm](<https://devfeed.tech/articles/auto-complete-craft-cms-3-apis-in-twig-with-phpstorm-31243.md>)

Original publisher: [Read original article](<https://nystudio107.com/blog/auto-complete-craft-cms-3-apis-in-twig-with-phpstorm>)

Author: andrew@nystudio107.com (Andrew Welch)

Published: 2019-03-17T22:55:00Z

Content type: tutorial

Language: en

Sources: [nystudio107 | Articles on modern web development.](<https://devfeed.tech/sources/nystudio107-articles-on-modern-web-development.md>)

Topics: [phpstorm](<https://devfeed.tech/topics/phpstorm.md>), [Content Management System](<https://devfeed.tech/topics/cms.md>), [PHP](<https://devfeed.tech/topics/php.md>)

Tags: [apis](<https://devfeed.tech/tags/apis.md>), [auto-complete](<https://devfeed.tech/tags/auto-complete.md>), [auto-completion](<https://devfeed.tech/tags/auto-completion.md>), [cms](<https://devfeed.tech/tags/cms.md>), [combined](<https://devfeed.tech/tags/combined.md>), [craft](<https://devfeed.tech/tags/craft.md>), [deprecated](<https://devfeed.tech/tags/deprecated.md>), [insights](<https://devfeed.tech/tags/insights.md>), [little](<https://devfeed.tech/tags/little.md>), [magic](<https://devfeed.tech/tags/magic.md>), [phpstorm](<https://devfeed.tech/tags/phpstorm.md>), [plugin](<https://devfeed.tech/tags/plugin.md>), [symfony](<https://devfeed.tech/tags/symfony.md>), [templates](<https://devfeed.tech/tags/templates.md>), [twig](<https://devfeed.tech/tags/twig.md>)

### AI overview

A deprecated tutorial explains how to configure PhpStorm's Symfony plugin and a faux Twig extension to enable Craft CMS API autocomplete in Twig templates. It recommends using the Craft Autocomplete package instead.

### Source excerpt

The Symfony plugin combined with a little magic will give you full auto-complete of all Craft CMS APIs in your Twig templates with PhpStorm!

## Twig Processing Order & Scope

DevFeed: [Twig Processing Order & Scope](<https://devfeed.tech/articles/twig-processing-order-scope-31310.md>)

Original publisher: [Read original article](<https://nystudio107.com/blog/twig-processing-order-and-scope>)

Author: andrew@nystudio107.com (Andrew Welch)

Published: 2016-11-28T15:31:00Z

Content type: tutorial

Language: en

Sources: [nystudio107 | Articles on modern web development.](<https://devfeed.tech/sources/nystudio107-articles-on-modern-web-development.md>)

Topics: [Template](<https://devfeed.tech/topics/template.md>), [Front end](<https://devfeed.tech/topics/frontend.md>), [Code](<https://devfeed.tech/topics/code.md>), [Content Management System](<https://devfeed.tech/topics/cms.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [frontend](<https://devfeed.tech/tags/frontend.md>), [important](<https://devfeed.tech/tags/important.md>), [insights](<https://devfeed.tech/tags/insights.md>), [language](<https://devfeed.tech/tags/language.md>), [little-known](<https://devfeed.tech/tags/little-known.md>), [order](<https://devfeed.tech/tags/order.md>), [processing](<https://devfeed.tech/tags/processing.md>), [scope](<https://devfeed.tech/tags/scope.md>), [templates](<https://devfeed.tech/tags/templates.md>), [templating](<https://devfeed.tech/tags/templating.md>), [twig](<https://devfeed.tech/tags/twig.md>), [understand](<https://devfeed.tech/tags/understand.md>)

### AI overview

This tutorial explains Twig's processing order and variable scope. It describes how extended, included, and block templates are processed, and why variables defined in one template context are not available in others.

### Source excerpt

The Twig templating language has a little-known processing order & scope that is important to understand