对象已移动

可在此处找到该文档 Apply an email template transformation from a module – New Self New Life
New Self New Life
No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
New Self New Life
No Result
View All Result
Home Softwares

Apply an email template transformation from a module

by admin
3 years ago
in Softwares
Apply an email template transformation from a module
Share on FacebookShare on Twitter


On this weblog, we’ll discover ways to apply the transformation in Prestashop trendy e-mail templates from a module.

The Prestashop has an TransformationInterface interface to change your template’s design simply. Listed below are the interface particulars:

<?php
namespace PrestaShopPrestaShopCoreMailTemplateTransformation;

interface TransformationInterface
{
    /**
     * @param string $templateContent
     * @param array $templateVariables
     *
     * @return string
     */
    public operate apply($templateContent, array $templateVariables);

    /**
     * Returns the kind of templates both html or textual content
     *
     * @return string
     */
    public operate getType();

    /**
     * @param LanguageInterface $language
     *
     * @return object
     */
    public operate setLanguage(LanguageInterface $language);
}

Go to the GitHub hyperlink https://github.com/PrestaShop/PrestaShop/blob/8.0.0/src/Core/MailTemplate/Transformation/TransformationInterface.php to get extra details about this interface.

The apply methodology receives the rendered structure as a string to carry out alternative and DOM manipulation.

In the event you don’t wish to modify it merely return the string with none adjustments. The getType methodology is used to filter transformations and the setLanguage methodology will can help you know concerning the language utilized in e-mail era to establish localized content material.

Looking for an skilled
Prestashop Firm ?
Learn Extra


Within the following instance, we’re utilizing a contemporary customized structure. If you wish to create a brand new structure then observe our different weblog.

{# modules/demoemail/mails/structure/customizable_modern_layout.html.twig #}
{% extends '@MailThemes/trendy/elements/structure.html.twig' %}

{% block content material %}
  <desk width="100%">
    <tr>
      <td align="middle" class="titleblock">
        <font dimension="2" face="{{ languageDefaultFont }}Open-sans, sans-serif" coloration="#555454">
          <span class="title">{{ 'That is an instance mail template from my module for contemporary theme'|trans({}, 'EmailsBody', locale)|uncooked }}</span>
        </font>
      </td>
    </tr>
    <tr>
      <td align="middle" class="titleblock">
        <font dimension="2" face="{{ languageDefaultFont }}Open-sans, sans-serif" coloration="#555454">
          <span class="customTitle">{{ exampleMsg }}</span>
        </font>
      </td>
    </tr>
    <tr>
      <td class="space_footer">&nbsp;</td>
    </tr>
  </desk>
{% endblock %}
Within the above code the <<robust><em>span class="customTitle"></em></robust> that comprises the message, we'll use this as a CSS selector to use our transformation.

Within the under code, we’ll create a category ExampleMsgColorTransformation that may prolong AbstractTransformation summary class. The AbstractTransformation class implements the TransformationInterface. The target of this class is to vary the colour of all of the <span> tags with the customTitle class.

<?php
namespace PrestaShopModuleDemoemailMailTemplateTransformation;

use PrestaShopPrestaShopCoreExceptionInvalidArgumentException;
use PrestaShopPrestaShopCoreMailTemplateMailTemplateInterface;
use PrestaShopPrestaShopCoreMailTemplateTransformationAbstractTransformation;
use SymfonyComponentDomCrawlerCrawler;
use DOMElement;

/**
 * Class ExampleMsgColorTransformation provides the customized coloration to all spans
 * with class subtitle.
 */
class ExampleMsgColorTransformation extends AbstractTransformation
{
    /** @var string */
    personal $customColor;

    /**
     * @param string $customColor
     * @throws InvalidArgumentException
     */
    public operate __construct($customColor)
    {
        mum or dad::__construct(MailTemplateInterface::HTML_TYPE);
        $this->customColor = $customColor;
    }

    /**
     * @inheritDoc
     */
    public operate apply($templateContent, array $templateVariables)
    {
        $crawler = new Crawler($templateContent);
        $customSpans = $crawler->filter('span[class="subtitle"]');
        /** @var DOMElement $customSpan */
        foreach ($customSpans as $customSpan) {
            $customSpan->setAttribute('model', sprintf('coloration: %s;', $this->customColor));
        }

        return $crawler->html();
    }
}

Now add your transformation for this structure, you could use the actionGetMailLayoutTransformations hook to render this from the module.

<?php
use PrestaShopPrestaShopCoreMailTemplateMailTemplateInterface;
use PrestaShopPrestaShopCoreMailTemplateMailTemplateRendererInterface;
use PrestaShopPrestaShopCoreMailTemplateLayoutLayoutInterface;
use PrestaShopPrestaShopCoreMailTemplateTransformationTransformationCollectionInterface;
use PrestaShopModuleDemoemailMailTemplateTransformationExampleMsgColorTransformation;

class Demoemail extends Module 
{
   public operate set up() 
   {
        return mum or dad::set up()
            && $this->registerHook(MailTemplateRendererInterface::GET_MAIL_LAYOUT_TRANSFORMATIONS)
        ;
    }
    
    public operate uninstall() 
    {
        return mum or dad::uninstall()
            && $this->unregisterHook(MailTemplateRendererInterface::GET_MAIL_LAYOUT_TRANSFORMATIONS)
        ;        
    }
    
    public operate allow() 
    {
        return mum or dad::allow()
            && $this->registerHook(MailTemplateRendererInterface::GET_MAIL_LAYOUT_TRANSFORMATIONS)
        ;
    }
    
    public operate disable() 
    {
        return mum or dad::disable()
            && $this->unregisterHook(MailTemplateRendererInterface::GET_MAIL_LAYOUT_TRANSFORMATIONS)
        ;        
    }
    
    /**
     * @param array $hookParams
     */
    public operate hookActionGetMailLayoutTransformations(array $hookParams)
    {
        if (!isset($hookParams['templateType']) ||
            MailTemplateInterface::HTML_TYPE !== $hookParams['templateType'] ||
            !isset($hookParams['mailLayout']) ||
            !isset($hookParams['layoutTransformations'])) {
            return;
        }

        /** @var LayoutInterface $mailLayout */
        $mailLayout = $hookParams['mailLayout'];
        if ($mailLayout->getModuleName() != $this->identify) {
            return;
        }

        /** @var TransformationCollectionInterface $transformations */
        $transformations = $hookParams['layoutTransformations'];
        $transformations->add(new ExampleMsgColorTransformation('#FF0000'));
    }
}
email_template

Now go to the “Design > E mail Theme” web page and preview your structure you will notice that your message has now modified its coloration.

email_template_1

That’s all about this weblog.

If any subject or doubt please be at liberty to say it within the remark part.

I’d be completely satisfied to assist.

Additionally, you possibly can discover our PrestaShop Improvement Companies & a wide range of high quality PrestaShop Modules.

For any doubt contact us at [email protected]

author-thumb

Amit Kumar Tiwari
3 Badges

10 December 2022



Source link

Tags: ApplyEmailModuletemplateTransformation
Previous Post

Uber files lawsuit to block NYC driver pay increase

Next Post

The Doom That Came to Gotham Movie

Related Posts

Meta and UK Government launch ‘Open Source AI Fellowship’
Softwares

Meta and UK Government launch ‘Open Source AI Fellowship’

by admin
July 12, 2025
Supervised vs Unsupervised Learning: Machine Learning Overview
Softwares

Supervised vs Unsupervised Learning: Machine Learning Overview

by admin
July 10, 2025
Minor update (2) for Vivaldi Desktop Browser 7.5
Softwares

Minor update (2) for Vivaldi Desktop Browser 7.5

by admin
July 9, 2025
20+ Best Free Food Icon Sets for Designers — Speckyboy
Softwares

20+ Best Free Food Icon Sets for Designers — Speckyboy

by admin
July 8, 2025
Luna v1.0 & FlexQAOA bring constraint-aware quantum optimization to real-world problems
Softwares

Luna v1.0 & FlexQAOA bring constraint-aware quantum optimization to real-world problems

by admin
July 7, 2025
Next Post
The Doom That Came to Gotham Movie

The Doom That Came to Gotham Movie

Glee ‘s Kevin McHale Speaks Out Against The Price of Glee Docuseries

Glee 's Kevin McHale Speaks Out Against The Price of Glee Docuseries

  • Trending
  • Comments
  • Latest
Kanye West entry visa revoked by Australia after ‘Heil Hitler’ song release – National

Kanye West entry visa revoked by Australia after ‘Heil Hitler’ song release – National

July 3, 2025
CBackup Review: Secure and Free Online Cloud Backup Service

CBackup Review: Secure and Free Online Cloud Backup Service

September 18, 2021
Every Van Halen Album, Ranked 

Every Van Halen Album, Ranked 

August 12, 2024
I Tried Calocurb For 90 Days. Here’s My Review.

I Tried Calocurb For 90 Days. Here’s My Review.

January 8, 2025
Bones: All Of Brennan’s Interns, Ranked

Bones: All Of Brennan’s Interns, Ranked

June 15, 2021
Clevo CO Review – A Complete Company Details

Clevo CO Review – A Complete Company Details

January 19, 2024
How to Build a DIY Spotify Music Player with Raspberry Pi Pico

How to Build a DIY Spotify Music Player with Raspberry Pi Pico

May 13, 2025
The Ballad of Songbirds and Snakes Cast & Character Guide

The Ballad of Songbirds and Snakes Cast & Character Guide

September 9, 2022
Jeff Lynne Pulls Out of Final ELO Show — See His Statement

Jeff Lynne Pulls Out of Final ELO Show — See His Statement

July 12, 2025
Crypto Billionaire Justin Sun Buys Another $100 Million of Trump’s Memecoin

Crypto Billionaire Justin Sun Buys Another $100 Million of Trump’s Memecoin

July 12, 2025
Paris Haute Couture Week 2025 Best Looks

Paris Haute Couture Week 2025 Best Looks

July 12, 2025
It’s the last day to get up to 50 percent off air fryers, Instant Pots, blenders and more

It’s the last day to get up to 50 percent off air fryers, Instant Pots, blenders and more

July 11, 2025
Hey r/movies! We’re Courtney Stephens and Callie Hernandez, the filmmakers of the recent meta-fictional, experimental feature film INVENTION, that’s now streaming on Mubi. You might also know Callie from La La Land, Alien: Covenant, Blair Witch, Under the Silver Lake, The Endless. Ask us anything!

Hey r/movies! We’re Courtney Stephens and Callie Hernandez, the filmmakers of the recent meta-fictional, experimental feature film INVENTION, that’s now streaming on Mubi. You might also know Callie from La La Land, Alien: Covenant, Blair Witch, Under the Silver Lake, The Endless. Ask us anything!

July 12, 2025
Meta and UK Government launch ‘Open Source AI Fellowship’

Meta and UK Government launch ‘Open Source AI Fellowship’

July 12, 2025
Best Amazon Prime Day 2025 Alternative Sales: Walmart, Target & More

Best Amazon Prime Day 2025 Alternative Sales: Walmart, Target & More

July 11, 2025
Michael Strahan’s extended silence raises questions during GMA absence

Michael Strahan’s extended silence raises questions during GMA absence

July 11, 2025
New Self New Life

Your source for entertainment news, celebrities, celebrity news, and Music, Cinema, Digital Lifestyle and Social Media and More !

Categories

  • Celebrity
  • Cinema
  • Devices
  • Digital Lifestyle
  • Entertainment
  • Music
  • Social Media
  • Softwares
  • Uncategorized

Recent Posts

  • Jeff Lynne Pulls Out of Final ELO Show — See His Statement
  • Crypto Billionaire Justin Sun Buys Another $100 Million of Trump’s Memecoin
  • Paris Haute Couture Week 2025 Best Looks
  • Home
  • Disclaimer
  • DMCA
  • Privacy Policy
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites. slotsfree  creator solana token

No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites.

New Self New Life