Prescribed way to set cookies (from plugin or Twig)
Cookies cannot be set via templates. However, in a plugin you have access to Craft's services. The UserSessionService has the saveCookie function.

craft()-&gt;userSession-&gt;saveCookie($cookieName, $data, $duration);