【问题标题】:How to override SonataUserBundle templates如何覆盖 SonataUserBundle 模板
【发布时间】:2014-05-22 08:49:31
【问题描述】:

我已经安装了 SonataAdminBundle 和 SonataUserBundle,我正在尝试覆盖一些树枝模板。除了 user_block.html.twig 之外,我已经成功完成了所有操作

这是我的项目 ../app/Resources/ 目录结构:

Resources/
├── ApplicationSonataUserBundle
│   └── views
│       ├── Admin
│       │   └── Core
│       │       └── user_block.html.twig   <--- it doesn't work
│       ├── layout.html.twig
│       ├── Profile
│       │   ├── action.html.twig
│       │   ├── edit_authentication.html.twig
│       │   ├── edit_profile.html.twig
│       │   └── show.html.twig
│       └── Security
│           └── login.html.twig
├── SonataAdminBundle
│   └── views
│       └── standard_layout.html.twig
└── TwigBundle
    └── views
        └── Exception
            └── error.html.twig

我也试过把它放在 SonataAdminBundle 或 SonataUserBundle 目录下,但没有,它对我不起作用。

如何覆盖 user_block 模板?

谢谢

【问题讨论】:

  • 请将您的答案发布为答案并将其标记为已接受!
  • 八小时后我才能回答,因为我的声望不够;)
  • @xabi82 你用什么来生成你的 ascii 目录树?
  • @codecowboy 我在 linux 系统上使用了“tree”命令。您可以在此链接后查看使用示例 -> computerhope.com/unix/tree.htm

标签: symfony sonata-admin sonata-user-bundle


【解决方案1】:

或者,您可以使用配置,如下所示:

sonata_admin:
    templates:
        layout:                 
        user_block: '::Admin/user_block.html.twig'

然后把你的模板放在这里:app/Resources/views/Admin/user_block.html.twig

【讨论】:

  • 感谢您提供替代解决方案 :)
【解决方案2】:

回答

之前显示的目录文件结构可以正常工作。我已经解决了这个问题,只需在 standard_layout.html.twig 上添加必要的 js 和 css

{% block stylesheets %}
            ...

            <!-- custom stylesheets -->
            <link rel="stylesheet" href="{{ asset('bundles/mybundle/css/mycssfile.css') }}" media="all">

{% endblock %}

{% block javascripts %}
            ...
            <!-- custom js -->
            <script src="{{ asset('bundles/mybundle/js/myscriptfile.css') }}"></script>

{% endblock %}

【讨论】:

猜你喜欢
  • 2015-02-08
  • 1970-01-01
  • 2023-01-26
  • 2012-09-19
  • 2011-07-08
  • 2017-09-03
  • 1970-01-01
  • 2013-06-21
  • 2018-12-16
相关资源
最近更新 更多