templates - Symfony 加载电子邮件的 Twig 模板

标签 templates symfony twig

加载期间 symfony twig 模板出现错误。

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

[InvalidArgumentException]

找不到模板“CrudBundle:email.html.twig”。

[Twig_Error_Loader]

找不到模板“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('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97e4f6fae7fbf2d7e4f6fae7fbf2b9f4f8fa" rel="noreferrer noopener nofollow">[email protected]</a>')
            ->setTo('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7201131f021e173201131f021e175c111d1f" rel="noreferrer noopener nofollow">[email protected]</a>')
            ->setBody(
                $this->getContainer()->get('templating')->render(
                    'CrudBundle:email.html.twig',
                    array('name' => $staffer->getUser())
                )
            )
        ;
        $this->get('mailer')->send($message);          
    }
}

请帮忙

最佳答案

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

关于templates - Symfony 加载电子邮件的 Twig 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15542225/

相关文章:

c++ - 根据作为参数接收的函数定义具有模板化键类型的 std::map

c++ - 在 C++ 中检查空循环

javascript - knockout 模板 : afterRender triggered twice because name/data are coupled observables

javascript - 在 symfony 中预览多个上传的图像

javascript - 使用 flatpickr 设置 minDate 变量

php - 我将如何在 Twig 中遍历这个关联数组?

c++ - 带类的标签分发

entity - 交响乐2 : Location of Entities

php - 如何让 API 平台加载相关(例如 Many2One)资源/实体?

angularjs - 将变量从 Symfony2 传递到 Angular 范围的最佳方法