{"id":40981,"date":"2016-02-11T12:06:39","date_gmt":"2016-02-11T12:06:39","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=40981"},"modified":"2016-02-11T12:11:42","modified_gmt":"2016-02-11T12:11:42","slug":"symfony-use-services-in-twig","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/","title":{"rendered":"Symfony &#8211; Use services in twig"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignnone size-medium wp-image-40972\" src=\"http:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet-300x95.png\" alt=\"Code-Snippet\" width=\"300\" height=\"95\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet-300x95.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet-250x79.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet-768x242.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet.png 825w\" sizes=\"(max-width: 300px) 100vw, 300px\" loading=\"lazy\" \/><\/p>\n<p><strong>Symfony Service : <\/strong>Service is any PHP object that performs some sort of &#8220;global&#8221; task.<\/p>\n<p>To access service in twig , you need to define service in config.yml files. Following is the example how to defined servies in config.yml :<\/p>\n<pre class=\"brush:xml\">twig:\r\n    globals:\r\n        test_service: \"@test.service\"\r\n<\/pre>\n<p>Now you service is globally accessible in twig, you can use service by simply<br \/>\nusing the following statement:<\/p>\n<pre class=\"brush:php\">{% set id = test_serive.getTestId() %}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Symfony Service : Service is any PHP object that performs some sort of &#8220;global&#8221; task. To access service in twig , you need to define service in config.yml files. Following is the example how to defined servies in config.yml : twig: globals: test_service: &#8220;@test.service&#8221; Now you service is globally accessible in twig, you can use <a href=\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":32,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2707,2708],"tags":[],"class_list":["post-40981","post","type-post","status-publish","format-standard","hentry","category-symfony","category-symfony2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Symfony - Use services in twig - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Symfony - Use services in twig - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Symfony Service : Service is any PHP object that performs some sort of &#8220;global&#8221; task. To access service in twig , you need to define service in config.yml files. Following is the example how to defined servies in config.yml : twig: globals: test_service: &quot;@test.service&quot; Now you service is globally accessible in twig, you can use [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-02-11T12:06:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-02-11T12:11:42+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet-300x95.png\" \/>\n<meta name=\"author\" content=\"Jitendra Singh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jitendra Singh\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/\"},\"author\":{\"name\":\"Jitendra Singh\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/b39e2ceab496d84ef098b5020a384109\"},\"headline\":\"Symfony &#8211; Use services in twig\",\"datePublished\":\"2016-02-11T12:06:39+00:00\",\"dateModified\":\"2016-02-11T12:11:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/\"},\"wordCount\":63,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet-300x95.png\",\"articleSection\":[\"Symfony\",\"Symfony2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/\",\"url\":\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/\",\"name\":\"Symfony - Use services in twig - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet-300x95.png\",\"datePublished\":\"2016-02-11T12:06:39+00:00\",\"dateModified\":\"2016-02-11T12:11:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#primaryimage\",\"url\":\"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet-300x95.png\",\"contentUrl\":\"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet-300x95.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Symfony &#8211; Use services in twig\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/b39e2ceab496d84ef098b5020a384109\",\"name\":\"Jitendra Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b12adc21e990c055e325a3c07339b3d4d313efd49f98a768c1a86fc7776f2b86?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b12adc21e990c055e325a3c07339b3d4d313efd49f98a768c1a86fc7776f2b86?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Jitendra Singh\"},\"sameAs\":[\"http:\/\/webkul.com\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/jitendra\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Symfony - Use services in twig - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/","og_locale":"en_US","og_type":"article","og_title":"Symfony - Use services in twig - Webkul Blog","og_description":"Symfony Service : Service is any PHP object that performs some sort of &#8220;global&#8221; task. To access service in twig , you need to define service in config.yml files. Following is the example how to defined servies in config.yml : twig: globals: test_service: \"@test.service\" Now you service is globally accessible in twig, you can use [...]","og_url":"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-02-11T12:06:39+00:00","article_modified_time":"2016-02-11T12:11:42+00:00","og_image":[{"url":"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet-300x95.png","type":"","width":"","height":""}],"author":"Jitendra Singh","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Jitendra Singh"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/"},"author":{"name":"Jitendra Singh","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/b39e2ceab496d84ef098b5020a384109"},"headline":"Symfony &#8211; Use services in twig","datePublished":"2016-02-11T12:06:39+00:00","dateModified":"2016-02-11T12:11:42+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/"},"wordCount":63,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#primaryimage"},"thumbnailUrl":"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet-300x95.png","articleSection":["Symfony","Symfony2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/","url":"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/","name":"Symfony - Use services in twig - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#primaryimage"},"thumbnailUrl":"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet-300x95.png","datePublished":"2016-02-11T12:06:39+00:00","dateModified":"2016-02-11T12:11:42+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#primaryimage","url":"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet-300x95.png","contentUrl":"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet-300x95.png"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/symfony-use-services-in-twig\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Symfony &#8211; Use services in twig"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/b39e2ceab496d84ef098b5020a384109","name":"Jitendra Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b12adc21e990c055e325a3c07339b3d4d313efd49f98a768c1a86fc7776f2b86?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b12adc21e990c055e325a3c07339b3d4d313efd49f98a768c1a86fc7776f2b86?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Jitendra Singh"},"sameAs":["http:\/\/webkul.com"],"url":"https:\/\/webkul.com\/blog\/author\/jitendra\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/40981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=40981"}],"version-history":[{"count":9,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/40981\/revisions"}],"predecessor-version":[{"id":40991,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/40981\/revisions\/40991"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=40981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=40981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=40981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}