[SOLVED] Converting PHP to Fusion Code

Because I didn’t work with TypoScript or Fusion so far I wonder if it’s possible to bring some PHP code in my Neos template. It’s just a small piece of code for reading a cookie but I could not find yet a way to bring this in my template.

<?php if(!(isset($_COOKIE['legalaccept']) && $_COOKIE['legalaccept'] == 'yes') ): ?>
        var legal = true;
<?php endif; ?>

Hello Bernhard,

look at the “request”-object that is available in the fusion-context:

# show the cookie __your_cookie_name__
debug = Neos.Fusion:Debug {
    value = ${request.parentRequest.cookies.__your_cookie_name__}

Something along those lines should do the trick:

# render tag based on cookie values
content = Neos.Fusion:Tag {
  @if.hasCookie = ${request.parentRequest.cookies.legalaccept && 
  request.parentRequest.cookies.legalaccept.value == 'yes' }
  tagName = "script" 
  content = 'var legal = true;'

# ensure sparate caching for users that accepted 
prototype(Neos.Fusion:GlobalCacheIdentifiers) {
  legalaccept = ${(request.parentRequest.cookies.legalaccept.value == 'yes')}

Hi Martin,

thank you very much for your detailed answer! This is really helpful for me!

Nice. Just one minor nitpick:
If you use request.httpRequest.* instead of request.parentRequest.* it keeps working even if nested in a plugin etc.