Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-03-09 18:31:44

phual
Member
From: UK
Registered: 2008-02-19
Posts: 26
Website

if_variable - why won't this work...

Ladies and gentleman, this is your once-in-a-half-hour opportunity to make me look like a tit! Don’t miss this wonderful opportunity, you’ll regret it if you do!

I’m trying to get what I think should be a very simple bit of code working, but for some reason, it won’t. Can someone please look at the code below and tell me what blindly obvious error (which I’m sure if will turn out to be) is causing this code to fail.


<txp:variable name="cookie_set">
  <txp:php>
    if (isset($_COOKIE["ancofe_cookie"])) {echo "true";}
    else {echo "false";}
  </txp:php>
</txp:variable>

<!DOCTYPE html>

<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>

<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc congue vulputate lorem nec vulputate. Mauris non euismod mi. Curabitur volutpat, arcu nec pharetra eleifend, lectus ligula sodales felis, quis dictum ligula erat nec felis. Sed et augue dui, et consequat enim. Integer eu dui tellus. Nulla consectetur nisl non nibh dictum lacinia dapibus enim elementum. Suspendisse sem enim, iaculis vel feugiat at, convallis id mauris. Curabitur risus nunc, cursus eu porttitor sit amet, ornare vitae arcu. Pellentesque justo diam, hendrerit ac egestas id, adipiscing sed tellus. </p>

<txp:if_variable name="cookie_set" value="false">
  <div id="move">
  This is a message. Please follow <a href="http://www.google.com#cookies">this link for info</a>.
  </div>
</txp:if_variable>

  </body>

</html>

If it matters, I’m still on version 4.2.0.

Thanks

Stuart

Offline

#2 2013-03-09 19:03:50

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,547
Website GitHub Twitter

Re: if_variable - why won't this work...

Hi

can you make <p><txp:variable name=“cookie_set” /></p> to see what is registred in the variable, maybe you have to deal with line breaks!

Cheers

Offline

#3 2013-03-09 19:55:26

phual
Member
From: UK
Registered: 2008-02-19
Posts: 26
Website

Re: if_variable - why won't this work...

You’ve made me a very happy man, and for two reasons:

1) you allowed me to identify the problem (whitespace / linebreaks)
2) it was subtle enough a problem that I don’t even feel like a tit!

With the hint, a little googling allowed me to identify this as a known issue.

For posterity, <p><txp:variable name=“cookie_set” /></p> was outputting the following:

<p>
false
</p>

when it should have been outputting

<p>false</p>

The two line breaks were causing the problem. The fix was to reformat the following code:

<txp:variable name="cookie_set">
  <txp:php>
    if (isset($_COOKIE["ancofe_cookie"])) {echo "true";}
    else {echo "false";}
  </txp:php>
</txp:variable>

as

<txp:variable name="cookie_set"><txp:php>
    if (isset($_COOKIE["ancofe_cookie"])) {echo "true";}
    else {echo "false";}
</txp:php></txp:variable>

I.e. remove two carriage returns. Frustrating little problem that.

Thanks

Stuart

Offline

#4 2013-03-09 20:00:16

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,547
Website GitHub Twitter

Re: if_variable - why won't this work...

Then have a good week end!

Offline

Board footer

Powered by FluxBB