定制 patrick-maynard/twig-stack-trace-dumper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

patrick-maynard/twig-stack-trace-dumper

最新稳定版本:v1.0.12

Composer 安装命令:

composer require patrick-maynard/twig-stack-trace-dumper

包简介

A Twig extension that allows the user to get a stack trace from within a template

README 文档

README

This Twig extension adds the trace() function to Twig.

It will output a string containing a stack trace.

I recommend only using it as a dev dependency. Using it in a production environment is probably not a good idea.

I created this tool for use in an environment where neither the Symfony toolbar nor XDebug was available.

Assuming you are able to use those better tools, I would urge you to do so.

Installation

To install this tool as a dev dependency:

composer require --dev patrick-maynard/twig-stack-trace-dumper

Configuration and usage

You'll then need to configure your app to have access to the extension.

Assuming you're using Symfony, you can do that using the instructions here: https://symfony.com/doc/current/templating/twig_extension.html#register-an-extension-as-a-service

Once that's done, you can use the new function in Twig files like this:

{{ trace()|raw }}

UPDATE: As of 2025, the Symfony documentation is pretty flippant about what you need to do to register your extension, essentially saying that it will be registered via magic. This is not always reliable, so you may or may not need to add something like the following to your services.yaml file:

    PatrickMaynard\TwigExtensions\Trace\StackTraceDumperExtension:
        tags: ['twig.extension']

If you want a little more detail than {{ trace()|raw }} provides, you could also try using {{ trace_via_debug_backtrace()|raw }} to get different formatting and some extra information. I have only done a smoke test on this. If you get a chance to write an integration test for this function, please open a pull request. Thank you.

Happy debugging!

统计信息

  • 总下载量: 60
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固