Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
PHP echo with article-custom ID attribute help please
Hey!
I don’t know PHP yet.
I got code that should display the title of article #1 but it’s not working for me :/
(I’m using raw PHP in a page)
Here is an example:
<?php
$articlenumber = '1';
$articletitle = '<a href="/'.$articlenumber.'"><txp:article_custom id="'.$articlenumber.'"><txp:title /></txp:article_custom></a>';
echo '
<div>'.$articletitle.'</div>
';
?>
What is wrong please?
The $articlenumber var in the A link HREF attribute works good,
but not in the article_custom ID attribute :(
Offline
Re: PHP echo with article-custom ID attribute help please
Try to wrap with parse()
and remember to use <txp:php>
if you are using php inside forms, pages or articles
<txp:php>
$articlenumber = ‘1’;
$articletitle = ‘<a href=”/’.$articlenumber.’”><txp:article_custom id=”’.$articlenumber.’”><txp:title /></txp:article_custom></a>’;
echo ‘
<div>’.parse($articletitle).’</div>
‘;
</txp:php>
Last edited by the_ghost (2010-06-13 07:23:39)
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
Re: PHP echo with article-custom ID attribute help please
Thanks it does works when using <txp:php>
but not with regular <?php after I set raw PHP to yes in the preferences.
What does really raw PHP means?
I just find it letting me using regular <?php tags instead of <txp:php> but is that what raw-PHP means please?
I got PHP code that if I enable the raw-php and use regular php tags it works good except of the txp-article-custom-id part.
but when I’m using <txp:php> I’m getting errors :/
You can see the code here (it’s the first code of – Retrieve/Manage comemnts)
You can see there that there are a lot of <?php ?> tags, and when I’m replacing them with <txp:php></txp:php> the code is not working good.
Offline
Re: PHP echo with article-custom ID attribute help please
Hi Gil
I’m wondering if you actually do need to struggle with php at all. rah_external can parse most txp tags which you can then just include their content in any php enabled page by using
<txp:php>include($DOCUMENT_ROOT . "http://www.yoursite.tld/?rah_external_output=name_here");</txp:php>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: PHP echo with article-custom ID attribute help please
colak wrote:
Hi Gil
I’m wondering if you actually do need to struggle with php at all.
Yes I do need to use PHP
Because I don’t know how to use the same code with the JS SDK yet.
but the problem must be something small and easy to fix.
if it’s works with txp:php so there should not be a problem to work with regular ?php tags and opposite.
Lets ask you this:
how do I convert this code to be right in txp please?
<?php if (!$fbme) { ?>
<div><fb:login-button size="medium">Connect with Facebook</fb:login-button></div>
You've to login to see and manage the comments.
<?php }else{ ?>
<div><fb:login-button size="medium" autologoutlink="true">Logout from Facebook</fb:login-button></div>
You are connected!
<?php } ?>
When I’m converting it to:
<txp:php> if (!$fbme) { </txp:php>
<div><fb:login-button size="medium">Connect with Facebook</fb:login-button></div>
You've to login to see and manage the comments.
<txp:php> }else{ </txp:php>
<div><fb:login-button size="medium" autologoutlink="true">Logout from Facebook</fb:login-button></div>
You are connected!
<txp:php> } </txp:php>
Then I’m getting this error:
Parse error: syntax error, unexpected $end in /textpattern/publish/taghandlers.php(3127) : eval()'d code on line 1
Offline
Re: PHP echo with article-custom ID attribute help please
<txp:php>
is a tag, and as all tags, it calls a function. As it is function and not normal ending and closing tags of PHP, slicing PHP like that won’t work. You will just end up with invalid PHP as every block is evaluated seperately. There’s a FAQ about the subject: Using PHP code in Textpattern.
Unlike with PHP’s end/closing tags, following won’t work:
<txp:php> if ($foo == $bar) {</txp:php>
True
<txp:php> }else{ </txp:php>
False
<txp:php> } </txp:php>
Instead, we have to do:
<txp:php>
if ($foo == $bar) {
echo 'True';
} else {
echo 'False';
}
</txp:php>
Thus, with the cut out you provided, we get the consept of:
<txp:php>
/*
[...] All the preding code.
*/
if (!$fbme) {
echo
'<div><fb:login-button size="medium">Connect with Facebook</fb:login-button></div>'.
'You've to login to see and manage the comments.';
} else {
echo
'<div><fb:login-button size="medium" autologoutlink="true">Logout from Facebook</fb:login-button></div>'.
'You are connected!';
}
/*
All appending code [...]
*/
</txp:php>
As the <txp:php>
tags do not work on global scope, you neither can transfer data from one block to another, neither you can continue parsing from one block to other. Instead, you need to put everything within one set of tags, or use PHP’s methods to transfer data from function to function.
Last edited by Gocom (2010-06-13 15:46:49)
Offline
Re: PHP echo with article-custom ID attribute help please
Thanks Jukka! working good now =)
Offline
Re: PHP echo with article-custom ID attribute help please
Hey again, I have the same problem but this time with JS
<script type="text/javascript">
$(document).ready(function() {
var aid = '1063';
var atitle = '<txp:article_custom id="'+aid+'"><txp:title /></txp:article_custom>';
$("#at").append(atitle);
});
</script>
<div id="at"></div>
It’s outputing nothing :/
Offline
Re: PHP echo with article-custom ID attribute help please
You can not pass a javascript (client side) variable to a txp tag (server side) in that way. What is aid
?
This will work:
<script type="text/javascript">
$(document).ready(function() {
var atitle = '<txp:article_custom id="1063"><txp:title /></txp:article_custom>';
$("#at").append(atitle);
});
</script>
<div id="at"></div>
Last edited by MattD (2010-07-08 22:55:49)
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: PHP echo with article-custom ID attribute help please
MattD wrote:
You can not pass a javascript (client side) variable to a txp tag (server side) in that way.
Ohh…ok, can I mix php into js?
If so I will love to know how please.
or maybe using Ajax? (I really have no idea)
MattD wrote:
What is
aid
?
article-id
it’s a variable that I’m getting after a FQL (SQL) Facebook call to they API.
that variable includes an article-id# that I want to use to get the title of the article using article-custom.
MattD wrote:
This will work:
Yes of course it is, but unfortunately it not helping me in this case :/
Offline
Re: PHP echo with article-custom ID attribute help please
You should understand the difference in javascript and php – JS is run by browser and PHP – by server. You want to get some data from txp:tag – this tags are parsed by server and return data to browser.
If you want to send data from JS to txp:tag (as you tried here) you can use ajax, for example.
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
Re: PHP echo with article-custom ID attribute help please
the_ghost wrote:
You should understand the difference in javascript and php – JS is run by browser and PHP – by server.
Yea now I will not forget it LOL ;)
the_ghost wrote:
If you want to send data from JS to txp:tag (as you tried here) you can use ajax, for example.
This is to much for my none programming knowledge,
can you please provide me a simple code?
Last edited by THE BLUE DRAGON (2010-07-08 23:50:46)
Offline