Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Content]: Revise "Extending Twig" > "Registering the Extension"

未关闭 适合新手
#790 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
68/100
Issue 类型
文档
描述清晰度
基本清楚
活跃度
活跃
技术栈
php
领域
documentation

调研方向

从 issue 中链接的“Registering the Extension”部分开始,并检查相应的文档源代码。审阅链接的 issue 中描述的 CKEditor 相关上下文,然后更新指南,使其准确说明何时适合进行 getIsSiteRequest() 检查;该部分应清楚地反映受支持的注册行为。

由索引模型根据 Issue 内容生成。

描述

Product

Craft CMS

Description

The docs mention this code in order to register Twig extensions:

if (Craft::$app->getRequest()->getIsSiteRequest()) {
    // Instantiate + register the extension:
    $extension = new mynamespace\myplugin\twig\Extension();
    Craft::$app->getView()->registerTwigExtension($extension);
}

And then states:

The getIsSiteRequest() check is optional. If your extension provides features that will be useful in system emails (commonly triggered from the control panel), or will be used when rendering templates from console requests (less common, but still valid), you may want to register it in all contexts.

However, since Craft 4.2.0 custom Twig functions are also used in CKEditor if it renders deeply nested partial templates that include CKEditor themselves. This results in issues like https://github.com/craftcms/ckeditor/issues/248 and https://github.com/craftcms/cms/issues/19639 (and I've also been asking for more context on this matter in https://github.com/craftcms/ckeditor/discussions/627). That's why I'd consider the getIsSiteRequest() check as actually harmful in Twig extension modules because now there are quite a few cases where Twig extensions are required in the CP as well.

Either this should get mentioned in the docs or the check should get removed completely (assuming the behavior of CKEditor doesn't change).

主要语言
JavaScript
星标
43
派生
160
平均合并
3 小时 9 分钟
30 天内合并 PR
4

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

craftcms/docs 的其他 Issue

查看 craftcms/docs 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。