Php 尝试使用swift mailer从节点访问要在电子邮件模板中呈现的值
我目前正在尝试使用构建电子邮件html模板。我现在的问题是如何自定义模板以从节点获取值并在电子邮件模板中呈现它们。仅从将发送的节点获取并打印/渲染节点值,如下面的屏幕截图所示 Swift mailer使用Php 尝试使用swift mailer从节点访问要在电子邮件模板中呈现的值,php,email,drupal,theming,Php,Email,Drupal,Theming,我目前正在尝试使用构建电子邮件html模板。我现在的问题是如何自定义模板以从节点获取值并在电子邮件模板中呈现它们。仅从将发送的节点获取并打印/渲染节点值,如下面的屏幕截图所示 Swift mailer使用{{body} 是否有一种方法可以访问字段中的值并在模板上呈现它们。类似于下面在节点模板上工作的代码 {{content.field\u title.value}或{{node.field\u title.value} Swift mailer有一种通过预处理呈现值的方法,但我似乎无法让它
{{body}
是否有一种方法可以访问字段中的值并在模板上呈现它们。类似于下面在节点模板上工作的代码
{{content.field\u title.value}
或{{node.field\u title.value}
Swift mailer有一种通过预处理呈现值的方法,但我似乎无法让它工作。下面是正在进行的工作的代码
在swiftmailer.html.twig中执行此操作后,您将能够呈现节点标题,如so{{node_title}@clestcruz,预处理是一个很好的选择。但您也可以为此创建服务 创建名为
foo
的自定义模块。
创建所有必需的文件,然后创建foo.services.yml
。
提及以下服务:
services:
foo.twig.TwigExtension:
class: Drupal\foo\XYZ
tags:
- {name: twig.extension}
在foo/src/XYZ.php中创建服务文件
<?php
namespace Drupal\foo;
use Drupal\block\Entity\Block;
use Drupal\user\Entity\User;
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\Core\Url;
/**
* Class DefaultService.
*
* @package Drupal\foo
*/
class XYZ extends \Twig_Extension {
/**
* {@inheritdoc}
* This function must return the name of the extension. It must be unique.
*/
public function getName() {
return 'product_listing_extend_display';
}
/**
* In this function we can declare the extension function.
*/
public function getFunctions() {
return array(
'getData' => new \Twig_Function_Method( $this, 'getData', array('is_safe' => array('html'))),
);
}
// Function to get tax childs by tid
function getData($id) {
// query for data
// return value
}
}
如何将节点传递给swiftmailer。用simplenews还是。。。?请尝试使用var_转储变量并检查其中的内容。预处理是正确的。@shaxaaa实际上还没有弄清楚如何将节点传递给swiftmailer。我还是一个初学者,所以像预处理
这样的事情我还没有弄明白是的,它总是一个节点的内容。我不确定您需要开发什么。@shaxaaa是的,它是一个节点的内容
services:
foo.twig.TwigExtension:
class: Drupal\foo\XYZ
tags:
- {name: twig.extension}
<?php
namespace Drupal\foo;
use Drupal\block\Entity\Block;
use Drupal\user\Entity\User;
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\Core\Url;
/**
* Class DefaultService.
*
* @package Drupal\foo
*/
class XYZ extends \Twig_Extension {
/**
* {@inheritdoc}
* This function must return the name of the extension. It must be unique.
*/
public function getName() {
return 'product_listing_extend_display';
}
/**
* In this function we can declare the extension function.
*/
public function getFunctions() {
return array(
'getData' => new \Twig_Function_Method( $this, 'getData', array('is_safe' => array('html'))),
);
}
// Function to get tax childs by tid
function getData($id) {
// query for data
// return value
}
}