Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#790 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
68/100
Loại issue
Tài liệu
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php
Lĩnh vực
documentation

Hướng nghiên cứu

Bắt đầu với phần “Registering the Extension” được liên kết trong issue và xem xét mã nguồn của tài liệu tương ứng. Xem lại ngữ cảnh liên quan đến CKEditor được mô tả trong các issue đã liên kết, sau đó cập nhật hướng dẫn để giải thích chính xác khi nào việc kiểm tra getIsSiteRequest() là phù hợp; phần này phải phản ánh rõ hành vi đăng ký được hỗ trợ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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).

Ngôn ngữ chính
JavaScript
Star
43
Fork
160
Merge trung bình
3 giờ 9 phút
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của craftcms/docs

Tất cả issue của craftcms/docs

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.