【问题标题】:Symfony Load Twig Template For EmailSymfony 为电子邮件加载 Twig 模板
【发布时间】:2013-03-21 08:04:22
【问题描述】:

在加载过程中我在 symfony 树枝模板中遇到错误。

我需要包含这个吗:使用 Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

[InvalidArgumentException]

Unable to find template "CrudBundle:email.html.twig".

[Twig_Error_Loader]

Unable to find template "CrudBundle:email.html.twig".

[Twig_Error_Loader]

Unable to find template "CrudBundle:email.html.twig" (looked into: C:\xampp
\htdocs\sample\vendor\symfony\symfony\src\Symfony\Bridge\Twig/Resourc
es/views/Form).

这是文件夹结构。

src/Btn/CrudBundle/command/SystemCommand.php:上课地点

src/Btn/CrudBundle/Resources/views/email.html.twig:模板位置

class SystemCommand extends ContainerAwareCommand
{

    protected function configure()
    {

        $this
            ->setName('cron:email:send')
            ->setDescription('Verifies that accounts');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln("This is a test");
        $message = \Swift_Message::newInstance()
            ->setSubject('Hello Email')
            ->setFrom('sample@sample.com')
            ->setTo('sample@sample.com')
            ->setBody(
                $this->getContainer()->get('templating')->render(
                    'CrudBundle:email.html.twig',
                    array('name' => $staffer->getUser())
                )
            )
        ;
        $this->get('mailer')->send($message);          
    }
}

请帮忙

【问题讨论】:

  • 您似乎忘记在模板名称中添加第二个冒号。 CrudBundle::email.html.twig。你也可以简单地使用 $this->render 而不是 $this->getContainer()->get('templating')->render

标签: templates symfony twig


【解决方案1】:

尝试CrudBundle::email.html.twig 而不是CrudBundle:email.html.twig

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多