[Content]: Revise "Extending Twig" > "Registering the Extension"
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 68/100
- Issue 类型
- 文档
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- php
调研方向
从 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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
craftcms/docs 的其他 Issue
-
Broken Link未关闭Broken Link
难度 1/5 1 小时以内 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 1/5 1-3 小时 新手友好度 68/100
-
Broken Link未关闭Broken Link
难度 1/5 1 小时以内 新手友好度 68/100
-
[Broken Link]:未关闭
难度 1/5 1 小时以内 新手友好度 65/100
相似的 Issue
-
curriculum documentation quality
难度 2/5 1-3 小时 新手友好度 78/100
githubnext/gh-aw-workshop#3897 ·
维护者通常 2 天内回复
-
agent/quality hive/hosted-available-lke648397-260827-5n31 quality testing
难度 2/5 1-3 小时 新手友好度 91/100
维护者通常 1 天内回复
-
check:failed feeds:add
难度 2/5 1-3 小时 新手友好度 70/100
iptv-org/database#36179 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复