PRO: JCI-twig-extensions for Cookies and http-forward

Set and Get Cookies

When you load a WordPress-Page, maybe also a Cookies is sent from you to the Server. E. g. a Session-Cookie which tells the Server that you are logged in.
Esp. by evaluating a sent cookie you’re able identify who is requesting the page and what data should be displayed therefore.

In a JCI-Template you load JSON-data from an API. But you show only those parts of the data which a loggedin user has rights for. Those rights can be managed by Cookies.
With a twig-function you can set and get cookie-data.

See this Example:

{% set setcookie = jci_setcookie('testname', 'testvalue') %}<hr>
{% set getcookie = jci_getcookie('testname') %}
getcookie: {{getcookie}}<hr>
{% if getcookie %}
cookie testname is set 
{% endif %}
show all cookies; {{ jci_getcookie() | json_encode }}
  • jci_setcookie(name, value=””, expires=0, path=””, domain=””, secure=false, httponly=false)
    is used like the PHP-setcookie
  • jci_getcookie(name)
    gives $_COOKIE[name]
  • jci_getcookie()
    gives the complete $_COOKIE with all Cookies

Forward to another Page



By sending a Location-Header you can force WordPress to jump to another page. This is very dangerous if you calc the target page dynamic, as you might forward to malicious pages!
So this should be used only if you know what you do!

It is helpful if you offer a form for inserting data, send this data to an API. Without forward a simple reload sends the data again and: If you want to display new and old data you hae to send an API-request again or process new and old data in the template.
With an forward you send the user to a page where a API-request is done only for displaying all data.


{{jci_forward(“a_new_url”) }}
Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.
On this page: