Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2012-10-02 18:10:03
- Quimbly
- Member
- Registered: 2012-07-12
- Posts: 22
Inserting PHP code block into content article
I’m struggling to do something seemingly simple: insert some markup into an article.
Here are the details:
- My user account permission level is publisher
- The site has all three PHP options enabled: Allow PHP in pages, Allow PHP in articles, Allow raw PHP
Inside an article, I’ve tried all of the following:
———————————————————————————————
Attempt #1
———————————————————————————————
<div class=“slideshow_test1”>
<img src=”/images/528.jpg” />
<img src=”/images/28.jpg” />
<img src=”/images/26.jpg” />
</div>
<script type=“text/javascript”>$(document).ready(function(){$(“.slideshow_test1”).cycle({ fx: “fade”, speed: 2000 }); }); </script>
———————————————————————————————
Attempt #2
———————————————————————————————
<txp:php>
<div class=“slideshow_test1”>
<img src=”/images/528.jpg” />
<img src=”/images/28.jpg” />
<img src=”/images/26.jpg” />
</div>
<script type=“text/javascript”>$(document).ready(function(){$(“.slideshow_test1”).cycle({ fx: “fade”, speed: 2000 }); }); </script>
</txp:php>
———————————————————————————————
Attempt #3
———————————————————————————————
<txp:php>
<?php
<div class=“slideshow_test1”>
<img src=”/images/528.jpg” />
<img src=”/images/28.jpg” />
<img src=”/images/26.jpg” />
</div>
<script type=“text/javascript”>$(document).ready(function(){$(“.slideshow_test1”).cycle({ fx: “fade”, speed: 2000 }); }); </script>
?>
</txp:php>
———————————————————————————————
Attempt #4
———————————————————————————————
<txp:php>
<?php
echo ‘
<div class=“slideshow_test1”>
<img src=”/images/528.jpg” />
<img src=”/images/28.jpg” />
<img src=”/images/26.jpg” />
</div>
<script type=“text/javascript”>$(document).ready(function(){$(“.slideshow_test1”).cycle({ fx: “fade”, speed: 2000 }); }); </script>’;
?>
</txp:php>
In each case, I get the following error:
Parse error: syntax error, unexpected ‘<’ in ……../textpattern/publish/taghandlers.php(3748) : eval()’d code on line 1
What am I missing??
Offline
#2 2012-10-02 18:53:01
- Quimbly
- Member
- Registered: 2012-07-12
- Posts: 22
Re: Inserting PHP code block into content article
Ok, finally figured it out… Not sure why this info is so hard to find!
This is the code block that eventually worked:
<notextile>
<txp:php>
echo ‘
<div class=“slideshow_test1”> <img src=”/images/528.jpg” /> <img src=”/images/28.jpg” /> <img src=”/images/26.jpg” />
</div>
<script type=“text/javascript”>$(document).ready(function(){$(”.slideshow_test1”).cycle({ fx: “fade”, speed: 2000 }); }); </script>’;
</txp:php>
</notextile>
So, here are my take-away lessons:
When inserting markup or PHP into a TextPattern content article:
1. Don’t include the usual PHP delineations: <?php … ?>
2. Use PHP, not mark-up:
e.g. Use this: echo ‘<div id=“abc”>blah blah blah</div>’; NOT this: <div id=“abc”>blah blah blah</div>3. Use must surround the code with both the <txp:php> and <notextile> tags:
e.g. <notextile> <txp:php> … code goes here … </txp:php> </notextile>Cheers.
Last edited by Quimbly (2012-10-02 20:44:57)
Offline
#3 2012-10-02 20:13:24
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Inserting PHP code block into content article
Glad you figured it out!
Quimbly wrote:
Not sure why this info is so hard to find!
Do you think this page is not clear enough? If so, any suggestions for improvements?
Offline
#4 2012-10-02 20:22:53
- Quimbly
- Member
- Registered: 2012-07-12
- Posts: 22
Re: Inserting PHP code block into content article
There are two problems with the link you provided:
1. That page did not turn up when I Googled the subject using these kinds of terms: textpatterm , insert/add PHP into content article.
2. There is no mention of the <notextile> tag on that page, which was a major stumbling block for me. I was basically following the method described on that page, but it didn’t work, and the error message was unhelpful.
Improvements: add a note about the <notextile> tag and maybe add better meta tags on the page for better search engine results.
Offline
Re: Inserting PHP code block into content article
That should cover it. I don’t know about meta tags and the wiki, but I added a heading that search engines should pick up.
Offline
#6 2012-10-02 20:41:52
- Quimbly
- Member
- Registered: 2012-07-12
- Posts: 22
Re: Inserting PHP code block into content article
Awesome! That should help others, I hope. Thanks, gang! You rock!
Offline
#7 2012-10-02 21:24:09
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Inserting PHP code block into content article
Nice, Marc, you beat me to it :)
maruchan wrote:
I added a heading that search engines should pick up.
Wouldn’t search engines pick it up if it were somewhere further on the page? I’m afraid you just violated the guidelines… ;)
I think we should ask Destry if we can have something like this.
Offline
Re: Inserting PHP code block into content article
I’m sure it’s not going to compete with many other pages on the web, so placing it just about anywhere would be fine with me. :-) Meta tags are alright but does Google use them for ranking purposes anymore? I thought they stopped doing that…
Offline
Re: Inserting PHP code block into content article
I’m confused because I don’t see what php code you were trying to insert. If you were trying to insert html markup with javascript then this should work.
notextile.. <div class="slideshow_test1"> <img src="/images/528.jpg" /> <img src="/images/28.jpg" /> <img src="/images/26.jpg" />
</div>
<script type="text/javascript">$(document).ready(function(){$(".slideshow_test1").cycle({ fx: "fade", speed: 2000 }); }); </script>
To break out of the notextile you’d just include a blank line and a p.
.
Last edited by MattD (2012-10-02 23:49:16)
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
#10 2012-10-03 03:22:42
- Quimbly
- Member
- Registered: 2012-07-12
- Posts: 22
Re: Inserting PHP code block into content article
Interesting! Ok, that makes sense.
I had no need to use PHP code other than to output the mark-up. I wasn’t aware of the <notextile> tag, so I had been experimenting with the <txp:php> tag. Again, I’m new to TextPattern, and when Googling, I had a hard time finding an answer to my seemingly simple task.
I’ve tested it out, and yes, if you’re just adding mark-up, the PHP tag is not needed. So, in my case, the following code block works just fine:
<notextile>
<div class=“slideshow_test1”> <img src=”/images/528.jpg” /> <img src=”/images/28.jpg” /> <img src=”/images/26.jpg” />
</div>
<script type=“text/javascript”>$(document).ready(function(){$(”.slideshow_test1”).cycle({ fx: “fade”, speed: 2000 }); }); </script>
</notextile>
Offline
Re: Inserting PHP code block into content article
Btw: Put your code snippet into a Textpattern ‘form’ and release it into the wild via <txp:output_form form="my_code_snippet" />
.
Btw II.: Reusable slideshow form: The mind bending <txp:yield /> inside a form is great for changing content like batches of pictures inside a txp:output_form
container.
Last edited by merz1 (2012-10-03 14:28:03)
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline
#12 2012-10-03 18:36:29
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: Inserting PHP code block into content article
Quimbly, after six years of working with TXP, I’m not yet certain enough in predicting in what cases I need to camouflage code in articles in order to not have it beautified by Textile, you’re not alone ;) With that said, however, taking a stab at your first attempt: I found the code works for me, it is there, on the page. So there might have been another problem at the time you tried.
But whenever I’m in doubt that code might get swallowed/come out unchanged, I use the quickly typed and easy to remember double equal ==<any code here />==
. No hassles whether it needs a blank space before or after or no space at all, it even works on a separate line.
Last edited by uli (2012-10-03 18:37:55)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline