Ad
How To Get Cookie In OctoberCMS
I've been made simple cookie. When user click button it save current time in cookie. My problem is that, I need to print that date and make a conditional.
I need to print cookie current time in default.htm or navbar.htm
This is what I have trying to add in
onStart() {
$cookie_time = htmlspecialchars($_COOKIE['get_date_time']);
}
and in navbar.htm
{{ cookie_time }}
but it's not printed or anything. When I check in browse my site stores that cookie correctly.
Ad
Answer
Although it is not the best, the way you are getting cookie value is fine. Your problem is in how you pass the value to the twig template.
The syntax to assign to $cookie_time
is wrong.
It should be like; $this['cookie_time'] = ...
Complete page code is this;
url = "/test"
==
public function onStart() {
$this['cookie_time'] = htmlspecialchars($_COOKIE['get_date_time']);
}
==
{{ cookie_time }}
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad