Split - "Hello World!" - Extension

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
CentaurAtlas
Registered User
Posts: 50
Joined: Sun Dec 02, 2007 5:39 pm
Contact:

Split - "Hello World!" - Extension

Post by CentaurAtlas »

Hey, this is a nice simple example, I have looked, but does anyone know if there are examples of using a php variable in the viewtopic_body_contact_fields_before.html for example? (I presume you'd have to have allow php in templates on.)

E.g. in a post you see the user ID, you see the rank, the number of posts, join date etc. Are there any examples of accessing that data from the extension file such as the one above, but it would be from any within the display list of posts loop.

Thanks! :-)
CentaurAtlas
Registered User
Posts: 50
Joined: Sun Dec 02, 2007 5:39 pm
Contact:

Re: "Hello World!" - Extension

Post by CentaurAtlas »

To answer my own question, you can access some variables like this:

Code: Select all

{postrow.POST_AUTHOR_FULL}
{postrow.POST_ID}
{postrow.RANK_TITLE}
Author: {postrow.U_POST_AUTHOR}
Post ID:{postrow.POST_ID}

Apparently you can not do this though to assign a PHP variable to a template variable, whereas in regular PHP you could do something similar:

Code: Select all

<!-- PHP -->
$PostID = <!-- ENDPHP -->{postrow.POST_ID}
<!-- PHP -->
;
<!-- ENDPHP -->

I was hoping to be able to get the ID in the PHP code and then be able to do things with the current post/poster etc, such as look up information.

Perhaps I am going about it the wrong way and there is another way to access that information.


CentaurAtlas wrote:Hey, this is a nice simple example, I have looked, but does anyone know if there are examples of using a php variable in the viewtopic_body_contact_fields_before.html for example? (I presume you'd have to have allow php in templates on.)

E.g. in a post you see the user ID, you see the rank, the number of posts, join date etc. Are there any examples of accessing that data from the extension file such as the one above, but it would be from any within the display list of posts loop.

Thanks! :-)
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 26935
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: "Hello World!" - Extension

Post by Paul »

If you want to do something with php, you should do it in the php files, not in the template files.
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development
CentaurAtlas
Registered User
Posts: 50
Joined: Sun Dec 02, 2007 5:39 pm
Contact:

Re: "Hello World!" - Extension

Post by CentaurAtlas »

Thanks for the reply - I am trying to familiarize myself with how the new extensions work.

I am trying to do something at a template event, viewtopic_body_contact_fields_before.html for example. To simplify, get the ID of the current poster in the display post event loop, and then look-up something, and use it in the output for that particular post. (Then repeat obviously for each post being displayed).

I think I see what you are saying. Do you have in mind creating a listener for that event, do the lookup there, then return the lookup as part of the post_row data? Then use it in the template/event/ html event file.

I have not done a PHPBB extension before, but have done them in Wordpress/BBPress, so apologies if the terminology is not correct. In WordPress, with a plugin you could trigger on the event, do the processing (both php and html) in the trigger, then use the results right there which is what I was thinking here at first.

;-)
CentaurAtlas
Registered User
Posts: 50
Joined: Sun Dec 02, 2007 5:39 pm
Contact:

Re: "Hello World!" - Extension

Post by CentaurAtlas »

After looking at things more, I don't think I need to use php, I can do it with the template code.

As a test so I can understand things better, I am trying to just take the viewtopic_body.html loop (lines 163-188) where it populates the profile-contact section in the post loop and replicate it in viewtopic_body_avatar_after.html except without the icons etc, just displaying the contacts in a row.



E.g.

Test code - I've essentially gotten rid of the need to have the DIVs after every 4 items, and all the markup, just to display the raw info, looping through the private message, email, website, twitter etc list. The ID, join date etc show, it gets into the IF S_IS_BOT/ENDIF section, but the loop never executes.

I'm sure I'm missing something obvious, but I am not sure where I messed up - given that other information is accessible in the event, am I right in assuming this is too?

Anything jump out at you? (I have been looking at this and the code for quite a while now!)

Code I have in viewtopic_body_avatar_after.html, just the loop doesn't execute, everything before and after does.

Code: Select all

Poster ID:{postrow.POSTER_ID}<br>
Joined:  {postrow.POSTER_JOINED}<br>
		<!-- IF not S_IS_BOT and .postrow.contact -->
							<!-- BEGIN contact -->
								ID: {postrow.contact.ID}
								NAME: {postrow.contact.NAME}
								CONTACT: {postrow.contact.U_CONTACT}
								AUTHOR:{postrow.U_POST_AUTHOR}
							<!-- BEGINELSE contact -->
								CONTACT ELSE
							<!-- END contact -->
	     after loop
		<!-- ENDIF -->


Original code from viewtopic_body.html :

Code: Select all

		<!-- IF not S_IS_BOT and .postrow.contact -->
			<dd class="profile-contact">
				<strong>{L_CONTACT}{L_COLON}</strong>
				<div class="dropdown-container dropdown-left">
					<a href="#" class="dropdown-trigger"><span class="imageset icon_contact" title="{postrow.CONTACT_USER}">{postrow.CONTACT_USER}</span></a>
					<div class="dropdown hidden">
						<div class="pointer"><div class="pointer-inner"></div></div>
						<div class="dropdown-contents contact-icons">
							<!-- BEGIN contact -->
								{% set REMAINDER = postrow.contact.S_ROW_COUNT % 4 %}
								<!-- DEFINE $S_LAST_CELL = ((REMAINDER eq 3) or (postrow.contact.S_LAST_ROW and postrow.contact.S_NUM_ROWS < 4)) -->
								<!-- IF REMAINDER eq 0 -->
									<div>
								<!-- ENDIF -->
									<a href="<!-- IF postrow.contact.U_CONTACT -->{postrow.contact.U_CONTACT}<!-- ELSE -->{postrow.U_POST_AUTHOR}<!-- ENDIF -->" title="{postrow.contact.NAME}"<!-- IF $S_LAST_CELL --> class="last-cell"<!-- ENDIF --><!-- IF postrow.contact.ID eq 'jabber' --> onclick="popup(this.href, 750, 320); return false;"<!-- ENDIF -->>
										<span class="contact-icon {postrow.contact.ID}-icon">{postrow.contact.NAME}</span>
									</a>
								<!-- IF REMAINDER eq 3 or postrow.contact.S_LAST_ROW -->
									</div>
								<!-- ENDIF -->
							<!-- END contact -->
						</div>
					</div>
				</div>
			</dd>
		<!-- ENDIF -->
Post Reply

Return to “Extension Writers Discussion”