Twig / Symfony 2.3.4:扩展存储在数据库中的Twig模板 [英] Twig / Symfony 2.3.4: Extending twig template stored in database

查看:122
本文介绍了Twig / Symfony 2.3.4:扩展存储在数据库中的Twig模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在Symfony 2.3.4中构建CMS,作为此CMS的一部分,我想将所有树枝模板存储在数据库中。我已经阅读了有关如何在数据库中存储和访问它们的内容,这看起来很简单-但是,仍然有一个问题。一定可以扩展存储在数据库中的模板,但是我不知道该怎么做。

I am currently building a CMS in Symfony 2.3.4, and as part of this CMS I would like to store all of the twig templates in a database. I've read up on how to store and access them in the database, and it seems simple enough - however, one question remains. It must be possible to extend templates stored in the database, but I have no idea how to do this.

如果有人有任何经验或知识,我将不胜感激。

If anybody has any experience or knowledge I would be very grateful.

干杯!

推荐答案

遵循 symfony论坛嫩枝食谱页面我能够将所有模板存储在数据库中,并进行扩展自动工作。但是请确保isFresh和getCacheKey返回值,否则由于某种原因您将获得无限递归。

Following the guides at the symfony forum and the Twig Recipes Page I was able to store all the templates in the database, and extending works automatically. Make sure that your isFresh and getCacheKey return values though, otherwise you will get an infinite recursion for some reason.

还值得注意的是,必须在数据库加载程序服务,而不是像symfony论坛所建议的那样添加chain_loader服务。

It is also worth noting that you must add a tag to the database loader service, instead of adding the chain_loader service as the symfony forum suggests.

vendor.bundle.twig_database_loader:
    class: Vendor\Bundle\Twig\TwigDatabaseLoader
    arguments: [ @doctrine.orm.entity_manager ]
    tags:
        - { name: twig.loader }

此代码会很好地工作。

这篇关于Twig / Symfony 2.3.4:扩展存储在数据库中的Twig模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆