Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6835451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:14:03+00:00 2026-05-26T23:14:03+00:00

I created new bundle (AcmeNotificationBundle) and I want to use it like a service

  • 0

I created new bundle (AcmeNotificationBundle) and I want to use it like a service like this:

$notification = $this->get( 'notification' );
$mess = $notification->getNotification( 'Some notification message' )->createView();

But in my bundle I need a twig service to render notification templates. I understand that I need something like this in Resources\config\services.yml file:

services:
twig:
    class: Path\To\Twig\Class

But I don’t know what is the right path to twig class. Аnyone encountered this problem? What is the right way to add twig service to bundle?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:14:03+00:00Added an answer on May 26, 2026 at 11:14 pm

    Templating service is already avaiable in your bundle. You can retrieve it from the container:

    $container->get('templating');
    

    You should be able to access twig service in a similar way:

    $container->get('twig');
    

    Rest of my answer uses templating service but you can easily replace it with twig if you really need to.

    I think what you need is passing templating service to your notification service.

    services:
        notification:
            class:     Acme\NotificationBundle\Notification
            arguments: [@templating]
    

    Your Notification class would take the templating as a constructor parameter:

    use Symfony\Bundle\TwigBundle\TwigEngine;
    
    class Notification
    {
        /**
         * @var Symfony\Bundle\TwigBundle\TwigEngine $templating
         */
        private $templating = null;
    
        /**
         * @param Symfony\Bundle\TwigBundle\TwigEngine $templating
         *
         * @return null
         */
        public function __construct(TwigEngine $templating)
        {
            $this->templating = $templating;
        }
    }
    

    Instead of $notification->getNotification('Some notification message')->createView() I’d probably do $notification->createNotificationView('Some notification message'). I’m assuming notification message is an entity and there’s no need to pass templating to the entity.

    Related documentation: Referencing (Injecting) Services

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a new ASP.NET MVC application. The home page looks like this: I
I created a new Visual Studio Setup project with VS 2008. I use it
I created a new View (LogView) in Infrastructure.Module project. This view will be used
I created a new content type for a wiki page library. I added this
I want to punt my sqlite db in to a custom bundle and use
In my small android application I created a Service to receive some string from
I've created new db via phpMyAdmin and while editing db privilages clicked delete localhost
I created a new SharePoint portal for testing purposes using a manually added HOSTS
I created a new email box for general support questions. When I try to
I created a new HalloWorld Makefile Project. There is a HalloWorld.cpp with my main

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.