Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
use the txp:php tag?
Hello there. I’m using textpattern for only a month and I am quit new to php as well. I am able to use the txp:php-tag, but right now, I’ve got some extra questions about it…
1) How do I create a var in one txp:php-tag and how do I reuse that var in another txp:php-tag on the same page/article/form?
2) I have a txp:php-tag in a form. There is php-code in that tag which is inserting a record in a database, but when I load the article containing the form, two records are inserted in the db, while this is not the case when I run the php-code without textpattern. Is there a simple manner to avoid this duplicate inserts? An url with guidelines or an explanation why textpattern needs to load the form twice is also welcome?
Thanks in advance,
GeertAki
Offline
Re: use the txp:php tag?
1) See the FAQ http://textpattern.com/faq/34/how-do-i-use-php-code (‘variable scope’)
2) ENable debug-mode and check the tagtrace to understand what is happening:
http://textpattern.com/faq/165/diagnosing-template-problems
Offline
Re: use the txp:php tag?
Thanks Sencer! I apologize that I overlooked the FAQ-part to help me out with question 1.
I know what causes problem 2, but I have no idea what the best solution is. On my page, I have an article in the big ‘content’-div, but in the sidebar (which is another location of my page), I also have a txp:article-tag, but with another article-form, displaying some of the custom-fields (which are not displayed by the first txp:article-tag) of my article. It is because of this second txp:article-tag that my article is loaded and rendered twice. Because I don’t display the article itself in the sidebar, the display is correct, but I can see in debug mode that the article is retrieved from the database twice and thus the insert is executed twice as well.
Is there a simple solution to tell textpattern to keep the article in memory for the current request or to only retrieve the fields that are displayed on the page?
Again, my apologies…
GeertAki
Offline
Re: use the txp:php tag?
Because I don’t display the article itself in the sidebar, the display is correct, but I can see in debug mode that the article is retrieved from the database twice and thus the insert is executed twice as well.
Incidentally one of the changes that are currently being tested for the next maintenance release (4.0.4) would probably solve your problem:
http://forum.textpattern.com/viewtopic.php?id=16139
If there are no compatibility problems or plugins that rely on the current behaviour, the above change would make it into the next minor release. If you feel comfortable with SVN, you could try those changes now on a test-site.
Offline
Re: use the txp:php tag?
Thanks for the tip, I will test the new code and post my remarks on it (positive or negative).
Greetings,
GeertAki
Offline
Pages: 1