Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
How do run code...
How do I run code through the textpattern parser from an outside file? What do i need to include in the php file, and what commands must I run?
Offline
#2 2005-10-22 20:19:47
- KurtRaschke
- Plugin Author
- Registered: 2004-05-16
- Posts: 275
Re: How do run code...
Fair warning, doing this will irritate the TXP “powers that be”, and they’ll start telling you what you can and can’t do with a piece of freely-released open source software. That aside, it’s always worked just fine for me. The exact method I use is documented here:
http://forum.textpattern.com/viewtopic.php?pid=75249#p75249
It’s true that Textpattern isn’t exactly built to work this way, but if it works for you, then great. If it causes problems, though, you may not be able to find anyone to fix it—you’re on your own for support.
-Kurt
Last edited by KurtRaschke (2005-10-22 20:22:06)
kurt@kurtraschke.com
Offline
#3 2005-10-22 22:17:06
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: How do run code...
they’ll start telling you what you can and can’t do with a piece of freely-released open source software
No, we’ll just point out exactly what you did: that Textpattern isn’t built to to embed in other applications, and that you’re on your own for problem solving.
Besides which, I’m not sure that C is asking about embedding Textpattern in something else. Including php code in a page template is covered in the FAQ. And you can run content through the Textpattern parser by passing a string to the parse()
function. Something like this perhaps:
<txp:php>echo parse(file_get_contents('/path/to/myfile.html'));</txp:php>
or:
<txp:php>
ob_start();
include('/path/to/myscript.php');
$out = ob_get_clean();
echo parse($out);
</txp:php>
You’ll have to make sure that the paths are correct, and that the included script doesn’t contain any class, function or variable names that clash with Textpattern.
Alex
Offline
#4 2005-10-22 23:29:40
- KurtRaschke
- Plugin Author
- Registered: 2004-05-16
- Posts: 275
Re: How do run code...
Zem: Sorry, point taken.
To get this back on-topic, regarding the case in which one wants to pull data out of TXP in an existing static PHP script, is there any interest in a library for doing so properly?
-Kurt
kurt@kurtraschke.com
Offline
Re: How do run code...
OK maybe if I explain what I want you guys could help me a bit more. Basically I want to add a page to txp, and i don’t want to do it the way I have been, I want it a seperate php file. So All I need is to get the content I want, into the txp wrapper, I am tried doing so by calling various MySQL querys, but it get VERY complicated with replacing all of the txp tags with the code that I want there. I just want a nice simple way to do it.
Offline
#6 2005-10-23 22:51:03
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: How do run code...
Either of those solutions I posted will work. You’ll need the second one if your file contains <?php ?>
tags. The first will allow <txp:php> .. </txp:php>
code, tho.
Sure you’re not overcomplicating things? You can put PHP code straight into Textpattern templates and forms.
Be aware that, however you do it, you’ll need to make sure any PHP code you run doesn’t clash with Textpattern (variable, class & function names, database connections, etc).
Alex
Offline
Re: How do run code...
Knowing me, I probbaly am over complicating it… hmmm I think my brain just thunkt! I think I know what i will do. Thank you dor your help, I may need it in the future :)
Offline
Re: How do run code...
OK i came up to organize it with txp. Now I am gettign this error when I goto the post:
“Parse error: parse error, unexpected ‘&’ in /REMOVED BECAUSE I WANTED TO/textpattern/publish/taghandlers.php(1533) : eval()’d code on line 98”
Bellow is the EXACTLY what is between the <txp:php> tags, ok well maybe I did remove the MySQl info, but still everythign else is the same
OK well I didn’t post it backe it was getting parsed by the board, so it is in a text file HERE: http://www.chiefbutz.info/hpguiz-code.txt
Offline
#9 2005-10-24 03:40:50
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: How do run code...
I suspect you’ve put the PHP code in an article body, correct? Try putting it in a Misc form instead, txp:php tags and all, and use <txp:output_form form="formname" />
in the article body.
I should add, this ought to fix the syntax error, but that doesn’t mean your script will necessarily work without modification. It looks like the kind of thing that would work well as a plugin – perhaps someone has already written one that’s similar. (Using Textpattern’s database functions rather than direct mysql_* calls would simplify your code)
Last edited by zem (2005-10-24 04:27:56)
Alex
Offline
Re: How do run code...
It would work better, as one, but it was originally a seperate PHP script, so I just didn’t bother with messing with it since I knew it worked.
Offline
Pages: 1