{"id":664,"date":"2026-06-17T06:59:06","date_gmt":"2026-06-17T06:59:06","guid":{"rendered":"https:\/\/www.hostx.ro\/kb\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\/"},"modified":"2026-07-26T14:46:20","modified_gmt":"2026-07-26T12:46:20","password":"","slug":"cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2","status":"publish","type":"docs","link":"https:\/\/www.hostx.ro\/kb\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\/","title":{"rendered":"Cum ob\u021bin adresa URL curent\u0103 \u00een blocurile \u0219i template-urile Magento 2?"},"content":{"rendered":"<p>Pentru a ob\u021bine URL-ul curent \u00eentr-un bloc sau template Magento 2, folose\u0219te <code>getCurrentUrl()<\/code> prin <code>StoreManagerInterface<\/code> injectat.<\/p>\n<h3>Clasa de bloc<\/h3>\n<pre><code>namespace Vendor\\Module\\Block;\n\nuse Magento\\Store\\Model\\StoreManagerInterface;\nuse Magento\\Framework\\View\\Element\\Template;\nuse Magento\\Framework\\View\\Element\\Template\\Context;\n\nclass Test extends Template\n{\n    private $storeManager;\n\n    public function __construct(\n        StoreManagerInterface $storeManager,\n        Context $context,\n        array $data = []\n    ) {\n        $this->storeManager = $storeManager;\n        parent::__construct($context, $data);\n    }\n\n    public function getCurrentUrl()\n    {\n        return $this->storeManager->getStore()->getCurrentUrl();\n    }\n}<\/code><\/pre>\n<h3>\u00cen template (.phtml)<\/h3>\n<pre><code>&lt;?= $block-&gt;escapeUrl($block-&gt;getCurrentUrl()) ?&gt;<\/code><\/pre>\n<p>Alternativ, pentru URL-ul rutei curente: <code>$block-&gt;getUrl('*\/*\/*', ['_current' =&gt; true, '_use_rewrite' =&gt; true])<\/code>. Gole\u0219te cache-ul dup\u0103 modific\u0103ri.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pentru a ob\u021bine URL-ul curent \u00eentr-un bloc sau template Magento 2, folose\u0219te getCurrentUrl() prin StoreManagerInterface injectat. Clasa de bloc namespace Vendor\\Module\\Block; use Magento\\Store\\Model\\StoreManagerInterface; use Magento\\Framework\\View\\Element\\Template; use Magento\\Framework\\View\\Element\\Template\\Context; class Test extends Template { private $storeManager; public function __construct( StoreManagerInterface $storeManager, Context $context, array $data = [] ) { $this->storeManager = $storeManager; parent::__construct($context, $data); } public function &#8230; <a title=\"Cum ob\u021bin adresa URL curent\u0103 \u00een blocurile \u0219i template-urile Magento 2?\" class=\"read-more\" href=\"https:\/\/www.hostx.ro\/kb\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\/\" aria-label=\"Cite\u0219te mai multe despre Cum ob\u021bin adresa URL curent\u0103 \u00een blocurile \u0219i template-urile Magento 2?\">Cite\u0219te mai mult<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"whmcs_kb_id":1815,"footnotes":""},"doc_category":[160],"doc_tag":[227,225,247,434],"class_list":["post-664","docs","type-docs","status-publish","hentry","doc_category-magento-programare-aplicatii","doc_tag-configurare","doc_tag-magento-2","doc_tag-php","doc_tag-template"],"year_month":"2026-11","word_count":109,"total_views":"20","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"name":"Adrian Firican","author_nicename":"techeditor1","author_url":"https:\/\/www.hostx.ro\/kb\/author\/techeditor1\/"},"doc_category_info":[{"term_name":"Magento","term_url":"https:\/\/www.hostx.ro\/kb\/docs-category\/magento-programare-aplicatii\/"}],"doc_tag_info":[{"term_name":"configurare","term_url":"https:\/\/www.hostx.ro\/kb\/docs-tag\/configurare\/"},{"term_name":"Magento 2","term_url":"https:\/\/www.hostx.ro\/kb\/docs-tag\/magento-2\/"},{"term_name":"PHP","term_url":"https:\/\/www.hostx.ro\/kb\/docs-tag\/php\/"},{"term_name":"template","term_url":"https:\/\/www.hostx.ro\/kb\/docs-tag\/template\/"}],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Ob\u021bine URL curent Magento 2 - Blocuri \u0219i Template - Centrul de suport HostX<\/title>\n<meta name=\"description\" content=\"Ob\u021bine adresa URL curent\u0103 \u00een Magento 2 folosind getCurrentUrl() prin StoreManagerInterface. Cod exemplu pentru blocuri \u0219i template-uri .phtml.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hostx.ro\/kb\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"ro_RO\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ob\u021bine URL curent Magento 2 - Blocuri \u0219i Template - Centrul de suport HostX\" \/>\n<meta property=\"og:description\" content=\"Ob\u021bine adresa URL curent\u0103 \u00een Magento 2 folosind getCurrentUrl() prin StoreManagerInterface. Cod exemplu pentru blocuri \u0219i template-uri .phtml.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hostx.ro\/kb\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Centrul de suport HostX\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-26T12:46:20+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Timp estimat pentru citire\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minut\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\\\/\",\"url\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\\\/\",\"name\":\"Ob\u021bine URL curent Magento 2 - Blocuri \u0219i Template - Centrul de suport HostX\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/#website\"},\"datePublished\":\"2026-06-17T06:59:06+00:00\",\"dateModified\":\"2026-07-26T12:46:20+00:00\",\"description\":\"Ob\u021bine adresa URL curent\u0103 \u00een Magento 2 folosind getCurrentUrl() prin StoreManagerInterface. Cod exemplu pentru blocuri \u0219i template-uri .phtml.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\\\/#breadcrumb\"},\"inLanguage\":\"ro-RO\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Prima pagin\u0103\",\"item\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"InfoCentru\",\"item\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/docs\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Cum ob\u021bin adresa URL curent\u0103 \u00een blocurile \u0219i template-urile Magento 2?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/#website\",\"url\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/\",\"name\":\"Centrul de suport HostX\",\"description\":\"tutoriale gazduire web, domenii web \u0219i servere\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hostx.ro\\\/kb\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ro-RO\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Ob\u021bine URL curent Magento 2 - Blocuri \u0219i Template - Centrul de suport HostX","description":"Ob\u021bine adresa URL curent\u0103 \u00een Magento 2 folosind getCurrentUrl() prin StoreManagerInterface. Cod exemplu pentru blocuri \u0219i template-uri .phtml.","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:\/\/www.hostx.ro\/kb\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\/","og_locale":"ro_RO","og_type":"article","og_title":"Ob\u021bine URL curent Magento 2 - Blocuri \u0219i Template - Centrul de suport HostX","og_description":"Ob\u021bine adresa URL curent\u0103 \u00een Magento 2 folosind getCurrentUrl() prin StoreManagerInterface. Cod exemplu pentru blocuri \u0219i template-uri .phtml.","og_url":"https:\/\/www.hostx.ro\/kb\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\/","og_site_name":"Centrul de suport HostX","article_modified_time":"2026-07-26T12:46:20+00:00","twitter_card":"summary_large_image","twitter_misc":{"Timp estimat pentru citire":"1 minut"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.hostx.ro\/kb\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\/","url":"https:\/\/www.hostx.ro\/kb\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\/","name":"Ob\u021bine URL curent Magento 2 - Blocuri \u0219i Template - Centrul de suport HostX","isPartOf":{"@id":"https:\/\/www.hostx.ro\/kb\/#website"},"datePublished":"2026-06-17T06:59:06+00:00","dateModified":"2026-07-26T12:46:20+00:00","description":"Ob\u021bine adresa URL curent\u0103 \u00een Magento 2 folosind getCurrentUrl() prin StoreManagerInterface. Cod exemplu pentru blocuri \u0219i template-uri .phtml.","breadcrumb":{"@id":"https:\/\/www.hostx.ro\/kb\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\/#breadcrumb"},"inLanguage":"ro-RO","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hostx.ro\/kb\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.hostx.ro\/kb\/cum-obtin-adresa-url-curenta-in-blocurile-si-template-urile-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Prima pagin\u0103","item":"https:\/\/www.hostx.ro\/kb\/"},{"@type":"ListItem","position":2,"name":"InfoCentru","item":"https:\/\/www.hostx.ro\/kb\/docs\/"},{"@type":"ListItem","position":3,"name":"Cum ob\u021bin adresa URL curent\u0103 \u00een blocurile \u0219i template-urile Magento 2?"}]},{"@type":"WebSite","@id":"https:\/\/www.hostx.ro\/kb\/#website","url":"https:\/\/www.hostx.ro\/kb\/","name":"Centrul de suport HostX","description":"tutoriale gazduire web, domenii web \u0219i servere","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hostx.ro\/kb\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ro-RO"}]}},"knowledge_base_info":[],"knowledge_base_slug":[],"_links":{"self":[{"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/docs\/664","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/comments?post=664"}],"version-history":[{"count":2,"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/docs\/664\/revisions"}],"predecessor-version":[{"id":5926,"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/docs\/664\/revisions\/5926"}],"wp:attachment":[{"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/media?parent=664"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/doc_category?post=664"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.hostx.ro\/kb\/wp-json\/wp\/v2\/doc_tag?post=664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}