How can i set global variable in Magento 2?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
The scenario is I want to set my variable to global variable from phtml file and call in module file or block file.
So any code or tutorial link that i set my variable to global and call in module or class file.
magento2 session global-variable
add a comment |Â
up vote
1
down vote
favorite
The scenario is I want to set my variable to global variable from phtml file and call in module file or block file.
So any code or tutorial link that i set my variable to global and call in module or class file.
magento2 session global-variable
check this link
– Hit's
2 hours ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
The scenario is I want to set my variable to global variable from phtml file and call in module file or block file.
So any code or tutorial link that i set my variable to global and call in module or class file.
magento2 session global-variable
The scenario is I want to set my variable to global variable from phtml file and call in module file or block file.
So any code or tutorial link that i set my variable to global and call in module or class file.
magento2 session global-variable
magento2 session global-variable
edited 3 mins ago


Sourabh Kumar Sharma
423214
423214
asked 2 hours ago
jhon jhon doe
1008
1008
check this link
– Hit's
2 hours ago
add a comment |Â
check this link
– Hit's
2 hours ago
check this link
– Hit's
2 hours ago
check this link
– Hit's
2 hours ago
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
1
down vote
Create your custom variable using System -> Custom Variables
.Using this you can add your global variable and use is anywhere in magento.
I want to set a variable in session and call on other page
– jhon jhon doe
49 mins ago
Hi Jhon please review this magento.stackexchange.com/questions/94265/…
– Shorabh
46 mins ago
add a comment |Â
up vote
1
down vote
You can use the code as below for setting up the session below code explains how to set a session in the customer session.
protected $customerSession;
public function __construct(
...
MagentoCustomerModelSession $customerSession,
...
)
...
$this->customerSession = $customerSession;
...
// later in your class you can use it as below
$this->customerSession->myName('anyname');
Few other sessions in Magento 2:
- MagentoBackendModelSession
- MagentoCatalogModelSession
- MagentoCheckoutModelSession
- MagentoCustomerModelSession
- MagentoNewsletterModelSession
Links to tutorials:
https://www.mageplaza.com/how-set-unset-session-magento-2.html
http://blog.chapagain.com.np/magento-2-set-unset-get-session/
add a comment |Â
up vote
0
down vote
To set and get global variable in Magento 2 to follow below steps
1) create the variable in admin side go to System -> Other Settings -> Custom Variables
2) add Variable Code, Variable Name, Variable HTML Value(if you want any html value into phtml file) and Variable Plain Value(if you want any plain value into phtml file)
3) get created variable value into phtml file or anywhere in your code
protected $objectManager;
public function __construct(
MagentoFrameworkObjectManagerInterface $objectManager
)
$this->_objectManager = $objectManager;
public function execute()
$model = $this->_objectManager->get('MagentoVariableModelVariable')->loadByCode('test_var');//your Variable Code
$plain_value = $model->getPlainValue();
$html_value = $model->getHtmlValue();
$name = $model->getName();
you can also set like a session variable and this one
New contributor
Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
how can i pass my own variable in it for example i save calue in variable and i want to pass that value on variable
– jhon jhon doe
43 mins ago
in your case, you should use session variable try this link as already mentioned in above answer
– Hit's
41 mins ago
yeah i use this links pls can you helo me that how can i echo that value in get message ?
– jhon jhon doe
40 mins ago
check here this is nice answer magento.stackexchange.com/a/209343 just replace setMessage or getMessage with your variable like setCalue and getCalue
– Hit's
35 mins ago
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Create your custom variable using System -> Custom Variables
.Using this you can add your global variable and use is anywhere in magento.
I want to set a variable in session and call on other page
– jhon jhon doe
49 mins ago
Hi Jhon please review this magento.stackexchange.com/questions/94265/…
– Shorabh
46 mins ago
add a comment |Â
up vote
1
down vote
Create your custom variable using System -> Custom Variables
.Using this you can add your global variable and use is anywhere in magento.
I want to set a variable in session and call on other page
– jhon jhon doe
49 mins ago
Hi Jhon please review this magento.stackexchange.com/questions/94265/…
– Shorabh
46 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Create your custom variable using System -> Custom Variables
.Using this you can add your global variable and use is anywhere in magento.
Create your custom variable using System -> Custom Variables
.Using this you can add your global variable and use is anywhere in magento.
answered 1 hour ago


Shorabh
457214
457214
I want to set a variable in session and call on other page
– jhon jhon doe
49 mins ago
Hi Jhon please review this magento.stackexchange.com/questions/94265/…
– Shorabh
46 mins ago
add a comment |Â
I want to set a variable in session and call on other page
– jhon jhon doe
49 mins ago
Hi Jhon please review this magento.stackexchange.com/questions/94265/…
– Shorabh
46 mins ago
I want to set a variable in session and call on other page
– jhon jhon doe
49 mins ago
I want to set a variable in session and call on other page
– jhon jhon doe
49 mins ago
Hi Jhon please review this magento.stackexchange.com/questions/94265/…
– Shorabh
46 mins ago
Hi Jhon please review this magento.stackexchange.com/questions/94265/…
– Shorabh
46 mins ago
add a comment |Â
up vote
1
down vote
You can use the code as below for setting up the session below code explains how to set a session in the customer session.
protected $customerSession;
public function __construct(
...
MagentoCustomerModelSession $customerSession,
...
)
...
$this->customerSession = $customerSession;
...
// later in your class you can use it as below
$this->customerSession->myName('anyname');
Few other sessions in Magento 2:
- MagentoBackendModelSession
- MagentoCatalogModelSession
- MagentoCheckoutModelSession
- MagentoCustomerModelSession
- MagentoNewsletterModelSession
Links to tutorials:
https://www.mageplaza.com/how-set-unset-session-magento-2.html
http://blog.chapagain.com.np/magento-2-set-unset-get-session/
add a comment |Â
up vote
1
down vote
You can use the code as below for setting up the session below code explains how to set a session in the customer session.
protected $customerSession;
public function __construct(
...
MagentoCustomerModelSession $customerSession,
...
)
...
$this->customerSession = $customerSession;
...
// later in your class you can use it as below
$this->customerSession->myName('anyname');
Few other sessions in Magento 2:
- MagentoBackendModelSession
- MagentoCatalogModelSession
- MagentoCheckoutModelSession
- MagentoCustomerModelSession
- MagentoNewsletterModelSession
Links to tutorials:
https://www.mageplaza.com/how-set-unset-session-magento-2.html
http://blog.chapagain.com.np/magento-2-set-unset-get-session/
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You can use the code as below for setting up the session below code explains how to set a session in the customer session.
protected $customerSession;
public function __construct(
...
MagentoCustomerModelSession $customerSession,
...
)
...
$this->customerSession = $customerSession;
...
// later in your class you can use it as below
$this->customerSession->myName('anyname');
Few other sessions in Magento 2:
- MagentoBackendModelSession
- MagentoCatalogModelSession
- MagentoCheckoutModelSession
- MagentoCustomerModelSession
- MagentoNewsletterModelSession
Links to tutorials:
https://www.mageplaza.com/how-set-unset-session-magento-2.html
http://blog.chapagain.com.np/magento-2-set-unset-get-session/
You can use the code as below for setting up the session below code explains how to set a session in the customer session.
protected $customerSession;
public function __construct(
...
MagentoCustomerModelSession $customerSession,
...
)
...
$this->customerSession = $customerSession;
...
// later in your class you can use it as below
$this->customerSession->myName('anyname');
Few other sessions in Magento 2:
- MagentoBackendModelSession
- MagentoCatalogModelSession
- MagentoCheckoutModelSession
- MagentoCustomerModelSession
- MagentoNewsletterModelSession
Links to tutorials:
https://www.mageplaza.com/how-set-unset-session-magento-2.html
http://blog.chapagain.com.np/magento-2-set-unset-get-session/
answered 19 mins ago


Sourabh Kumar Sharma
423214
423214
add a comment |Â
add a comment |Â
up vote
0
down vote
To set and get global variable in Magento 2 to follow below steps
1) create the variable in admin side go to System -> Other Settings -> Custom Variables
2) add Variable Code, Variable Name, Variable HTML Value(if you want any html value into phtml file) and Variable Plain Value(if you want any plain value into phtml file)
3) get created variable value into phtml file or anywhere in your code
protected $objectManager;
public function __construct(
MagentoFrameworkObjectManagerInterface $objectManager
)
$this->_objectManager = $objectManager;
public function execute()
$model = $this->_objectManager->get('MagentoVariableModelVariable')->loadByCode('test_var');//your Variable Code
$plain_value = $model->getPlainValue();
$html_value = $model->getHtmlValue();
$name = $model->getName();
you can also set like a session variable and this one
New contributor
Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
how can i pass my own variable in it for example i save calue in variable and i want to pass that value on variable
– jhon jhon doe
43 mins ago
in your case, you should use session variable try this link as already mentioned in above answer
– Hit's
41 mins ago
yeah i use this links pls can you helo me that how can i echo that value in get message ?
– jhon jhon doe
40 mins ago
check here this is nice answer magento.stackexchange.com/a/209343 just replace setMessage or getMessage with your variable like setCalue and getCalue
– Hit's
35 mins ago
add a comment |Â
up vote
0
down vote
To set and get global variable in Magento 2 to follow below steps
1) create the variable in admin side go to System -> Other Settings -> Custom Variables
2) add Variable Code, Variable Name, Variable HTML Value(if you want any html value into phtml file) and Variable Plain Value(if you want any plain value into phtml file)
3) get created variable value into phtml file or anywhere in your code
protected $objectManager;
public function __construct(
MagentoFrameworkObjectManagerInterface $objectManager
)
$this->_objectManager = $objectManager;
public function execute()
$model = $this->_objectManager->get('MagentoVariableModelVariable')->loadByCode('test_var');//your Variable Code
$plain_value = $model->getPlainValue();
$html_value = $model->getHtmlValue();
$name = $model->getName();
you can also set like a session variable and this one
New contributor
Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
how can i pass my own variable in it for example i save calue in variable and i want to pass that value on variable
– jhon jhon doe
43 mins ago
in your case, you should use session variable try this link as already mentioned in above answer
– Hit's
41 mins ago
yeah i use this links pls can you helo me that how can i echo that value in get message ?
– jhon jhon doe
40 mins ago
check here this is nice answer magento.stackexchange.com/a/209343 just replace setMessage or getMessage with your variable like setCalue and getCalue
– Hit's
35 mins ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
To set and get global variable in Magento 2 to follow below steps
1) create the variable in admin side go to System -> Other Settings -> Custom Variables
2) add Variable Code, Variable Name, Variable HTML Value(if you want any html value into phtml file) and Variable Plain Value(if you want any plain value into phtml file)
3) get created variable value into phtml file or anywhere in your code
protected $objectManager;
public function __construct(
MagentoFrameworkObjectManagerInterface $objectManager
)
$this->_objectManager = $objectManager;
public function execute()
$model = $this->_objectManager->get('MagentoVariableModelVariable')->loadByCode('test_var');//your Variable Code
$plain_value = $model->getPlainValue();
$html_value = $model->getHtmlValue();
$name = $model->getName();
you can also set like a session variable and this one
New contributor
Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
To set and get global variable in Magento 2 to follow below steps
1) create the variable in admin side go to System -> Other Settings -> Custom Variables
2) add Variable Code, Variable Name, Variable HTML Value(if you want any html value into phtml file) and Variable Plain Value(if you want any plain value into phtml file)
3) get created variable value into phtml file or anywhere in your code
protected $objectManager;
public function __construct(
MagentoFrameworkObjectManagerInterface $objectManager
)
$this->_objectManager = $objectManager;
public function execute()
$model = $this->_objectManager->get('MagentoVariableModelVariable')->loadByCode('test_var');//your Variable Code
$plain_value = $model->getPlainValue();
$html_value = $model->getHtmlValue();
$name = $model->getName();
you can also set like a session variable and this one
New contributor
Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 31 mins ago
New contributor
Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 1 hour ago
Hit's
1536
1536
New contributor
Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Hit's is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
how can i pass my own variable in it for example i save calue in variable and i want to pass that value on variable
– jhon jhon doe
43 mins ago
in your case, you should use session variable try this link as already mentioned in above answer
– Hit's
41 mins ago
yeah i use this links pls can you helo me that how can i echo that value in get message ?
– jhon jhon doe
40 mins ago
check here this is nice answer magento.stackexchange.com/a/209343 just replace setMessage or getMessage with your variable like setCalue and getCalue
– Hit's
35 mins ago
add a comment |Â
how can i pass my own variable in it for example i save calue in variable and i want to pass that value on variable
– jhon jhon doe
43 mins ago
in your case, you should use session variable try this link as already mentioned in above answer
– Hit's
41 mins ago
yeah i use this links pls can you helo me that how can i echo that value in get message ?
– jhon jhon doe
40 mins ago
check here this is nice answer magento.stackexchange.com/a/209343 just replace setMessage or getMessage with your variable like setCalue and getCalue
– Hit's
35 mins ago
how can i pass my own variable in it for example i save calue in variable and i want to pass that value on variable
– jhon jhon doe
43 mins ago
how can i pass my own variable in it for example i save calue in variable and i want to pass that value on variable
– jhon jhon doe
43 mins ago
in your case, you should use session variable try this link as already mentioned in above answer
– Hit's
41 mins ago
in your case, you should use session variable try this link as already mentioned in above answer
– Hit's
41 mins ago
yeah i use this links pls can you helo me that how can i echo that value in get message ?
– jhon jhon doe
40 mins ago
yeah i use this links pls can you helo me that how can i echo that value in get message ?
– jhon jhon doe
40 mins ago
check here this is nice answer magento.stackexchange.com/a/209343 just replace setMessage or getMessage with your variable like setCalue and getCalue
– Hit's
35 mins ago
check here this is nice answer magento.stackexchange.com/a/209343 just replace setMessage or getMessage with your variable like setCalue and getCalue
– Hit's
35 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f245162%2fhow-can-i-set-global-variable-in-magento-2%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
check this link
– Hit's
2 hours ago