Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2014-10-21 21:01:52
- ingleslenobel
- Member
- Registered: 2014-10-16
- Posts: 88
include php snippet?
May I ask if this is possible:
I would like to add a blog to my extreme macro site , one just with “by date/month” category and descriptive categories. I like textpattern because it seems very fast (less included files). But I already have a database with user comments on existing articles on my site. I should like to put the comment script that allows users to make these comments as the add comment functionality on textpattern pages. This is to store everything in one place because my site already has a sitewide “recent comments” sidebar which also feeds a ‘pages recently updated’ sidebox on the homepage (based on file save date). The comment script clearly requires a database call etc to a different database, and php snippets from that script. Not a problem, except… how do I add a php snippet into page templates that I can the customise variable values for on a page by page basis?
Thank you for your time
Offline
Re: include php snippet?
ingleslenobel wrote #285025:
how do I add a php snippet into page templates
Use <txp:php> // Your code here </txp:php>
.
Some things to bear in mind:
- You need to check that PHP in page templates is enabled from Admin ->Advanced prefs.
- Anything you wish to reference from outside this block must be declared
global
. - You cannot dive in and out of
<txp:php>
tags like you can with raw<?php ... ?>
tags. So you cannot, for example, start a conditional in one block, drop out of the block and conclude the conditional statement in another block. Each<txp:php>
block must be self-contained and must, as mentioned above, share any variables with other blocks by using theglobal
keyword in front of the variable name.
Example:
<txp:php>
global $myCounter;
$myCounter = 4;
</txp:php>
... some regular txp:tags here...
<txp:php>
global $myCounter;
$myCounter++;
echo $myCounter; // Will show 5.
</txp:php>
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#3 2014-10-21 21:45:59
- ingleslenobel
- Member
- Registered: 2014-10-16
- Posts: 88
Re: include php snippet?
Ahhh, fantastic, thank you so very much. And thanks for the pointers, highly appreciated.
-Johan
Offline
Pages: 1