How to use post id as php value

Discussion forum for MOD Writers regarding MOD Development.
atoirtap
Registered User
Posts: 63
Joined: Thu Aug 01, 2013 8:34 pm

How to use post id as php value

Post by atoirtap »

Hi buddies. I'm trying to add a minor hack in viewtopic_body.html to add some external data and show them near the poster's name and avatar. To get this goal, I need to use the post id value. But I'm not sure how to do it.

I thought about adding in the adequate place in viewtopic_body.html something like:

...
<!-- PHP -->
query to external data handling post id
echo result
<!-- ENDPHP -->
...

But, despite it's available {postrow.POST_ID} in viewtopic_body.html, I don't how to handle it inside the php block (I would need to assign it to a php variable).

I know this kind of sutff should be avoided as much as possible inside templates files, so I could maybe do something like,

...
<!-- INCLUDEPHP somefile.php -->
...

But still don't know how to get and handle post id.

Any help? :)
FoulFoot
Registered User
Posts: 262
Joined: Mon Jun 23, 2003 1:04 am
Location: Honolulu, HI

Re: How to use post id as php value

Post by FoulFoot »

You don't wan't to include php code in the HTML template file. Instead, look in viewtopic.php to see how it outputs data to the template array. Search for $postrow. Include a line such as:

Code: Select all

'MYDATA'		=> 'http://database.com?postid=' . $row['post_id'],
... as a basic example.

Foul
atoirtap
Registered User
Posts: 63
Joined: Thu Aug 01, 2013 8:34 pm

Re: How to use post id as php value

Post by atoirtap »

Thanks for answering. I know about not adding php in templates files (I said it by myself in mi previous post). Anyway, I don't completely understand your example.
FoulFoot
Registered User
Posts: 262
Joined: Mon Jun 23, 2003 1:04 am
Location: Honolulu, HI

Re: How to use post id as php value

Post by FoulFoot »

Search for "$postrow" in viewtopic.php. That will show you the array that outputs data to the template. Within that array, you can add a line that sends the data you want. $row['post_id'] is the variable that contains the post_id. Make more sense?

Foul
atoirtap
Registered User
Posts: 63
Joined: Thu Aug 01, 2013 8:34 pm

Re: How to use post id as php value

Post by atoirtap »

Thanks for answering. I think we're not understanding each other... I know all that, I know that 'POST_ID'=> $row['post_id'] is contained in the postrow array in viewtopic.php, so {postrow.POST_ID} can be used as a template variable in viewtopic_body.html, but still don't know how to use that template variable inside a php block... I know too that the 'right proceed' is adding this stuff in viewtopic.php, but it's a quite minor hack...

Anyway, changing a little the point of view, is it possible to 'send' a variable (say post_id contained in /root/phpbb/viewtopic.php) to a php file (say /root/stuff.php) to use it in this php file?
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28936
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier

Re: How to use post id as php value

Post by Paul »

It would require a lot of less hacking if you add your php code to the right place, the php file (So in your case viewtopic.php)
atoirtap
Registered User
Posts: 63
Joined: Thu Aug 01, 2013 8:34 pm

Re: How to use post id as php value

Post by atoirtap »

Sure? I want to add something like this

...
function isPrime($num)
...
query to external database
get variable from query (say $var)
if isPrime(post_id/$var) then echo stuff
...
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28936
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier

Re: How to use post id as php value

Post by Paul »

Yes? phpBB is completly made with the template system in mind, so I don't see why it would't work for you. Instead of using echo you just assign the resulting data to the template system, and in the template you have the specific template variable in the right location.
atoirtap
Registered User
Posts: 63
Joined: Thu Aug 01, 2013 8:34 pm

Re: How to use post id as php value

Post by atoirtap »

Thanks for your advise, Paul. Anyway, do you mind to kindly teach me how to handle a template variable inside a php block, as an exceptional non-habitual and very limited minor hack?

Return to “[3.0.x] MOD Writers Discussion”