Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-01-27 00:22:46

Jeff_K
Archived Plugin Author
From: Vancouver, British Columbia
Registered: 2005-08-19
Posts: 202
Website

output article body from within php conditional

On an article form, I am using php to test the value of a Cookie to see if a person in logged into the <a href=“http://fillip.ca”>Fillip</a> site. If someone has entered the password then the artcle form should output the article body. Else, it should output the article except and a misc form that explains where they can buy the issue in which the article appeared.

Testing for the cookie is no problem, I am just having trouble outputting the article except and body from within php. Following <a href=“http://textpattern.com/faq/160/can-i-use-tags-within-tags”>this</a>, I have tried:

<code>
<?php
if ($COOKIE[‘login’] == $GOLBAL[‘password’])
echo body($GLOBALS[‘thisarticle’]);
else echo except($GLOBALS[‘thisarticle’]);
?>
</code>

I have also tried <code>echo output_form(array(‘form’ => ‘form_name’));</code>.

Niether outputs any data. A look at the taghandler.php file helped, but I still can’t figure it out. Help would be appreciated. Jeff.

Last edited by Jeff_K (2006-01-27 00:24:03)

Offline

#2 2006-01-27 00:34:48

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: output article body from within php conditional

For starters, turn on Debugging mode. That will give you some hints – i.e. the body() and except() functions don’t exist.

Start with var_dump($thisarticle);


Alex

Offline

#3 2006-01-27 00:36:55

Jeff_K
Archived Plugin Author
From: Vancouver, British Columbia
Registered: 2005-08-19
Posts: 202
Website

Re: output article body from within php conditional

Okay, so I guess I jumped the gun. I found a solution that works:

<code> <?php if ($_COOKIE[‘login’] == $GLOBALS[‘password’]) { ?> <txp:body /> <?php } else { ?> <txp:excerpt /> <txp:output_form form=“preview_notice” /> <?php } ?>
</code>

If anyone knows a way of access body and except functions wouldn’t require exiting php, I would be interested to know.

Offline

#4 2006-01-27 00:39:06

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: output article body from within php conditional

This won’t work in many instances. Use <txp:php>, not < ?php..


Alex

Offline

#5 2006-01-27 00:51:10

Jeff_K
Archived Plugin Author
From: Vancouver, British Columbia
Registered: 2005-08-19
Posts: 202
Website

Re: output article body from within php conditional

Alex, Thanks for the tip.

I tried replacing <code><-?php</code> and <code>?></code> with <code><txp:php></code> and <code></txp:php></code>. But now everything outputs (the if echo and else echo) and I get <code>Parse error: parse error, unexpected $ in /public_html/textpattern/publish/taghandlers.php(1726) : eval()’d code on line 1</code> and <code>Parse error: parse error, unexpected ‘}’ in /public_html/textpattern/publish/taghandlers.php(1726) : eval()’d code on line 1</code>.

Last edited by Jeff_K (2006-01-27 00:53:45)

Offline

#6 2006-01-27 01:12:10

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: output article body from within php conditional

PHP is telling you that there’s an error in your code. See the FAQ.

Probably what you want is something like <txp:php>global $thisarticle; if (something) echo $thisarticle['Body_html']; ...


Alex

Offline

#7 2006-01-27 02:18:25

Jeff_K
Archived Plugin Author
From: Vancouver, British Columbia
Registered: 2005-08-19
Posts: 202
Website

Re: output article body from within php conditional

After a far bit of fussing, I managed to get everything up and running using <code><txp:php></code> (the debugging mode suggestion was a huge help). Still have a pesky undefined index error when the cookie has not been set, but I am sure I can fix that eventually.

Offline

Board footer

Powered by FluxBB