Add data to custom panel

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
danitav93
Registered User
Posts: 15
Joined: Sun Jan 28, 2018 5:11 pm

Add data to custom panel

Post by danitav93 » Sat Mar 03, 2018 5:43 pm

Hello everybody!
I have a custom panel built with posting_editor_add_panel_tab event. Inside the panel's body (posting_layout_include_panel_body) there is a simple table element:

Code: Select all

<table id="tableId"  name="table">		
</table>
When a user edits a post I want to populate the table with data from DB that depend on post_id. I tried to handle some events like core.topic_review_modify_row where I can retrieve the post_id but I cannot figure out how to pass data to the table.

Thanks for any help.

User avatar
znaeff
Registered User
Posts: 20
Joined: Thu Jul 25, 2013 5:07 am
Name: Alexey Znaev
Contact:

Re: Add data to custom panel

Post by znaeff » Wed Mar 28, 2018 7:17 pm

Hello danitav93,

I guess this is what you need:

1) In your html template:

Code: Select all

		
<table class="table1 zebra-table">
	<thead>
		<tr>
		<th>ID</th>
		<th>DATA</th>
		</tr>
	</thead>
	<tbody>
	<!-- BEGIN DB_DATA -->
		<tr>
		<td style="vertical-align: top;">{DB_DATA.ID}</td>
		<td style="vertical-align: top;">{DB_DATA.DATA}</td>
		</tr>
	<!-- END DB_DATA -->
	</tbody>
</table>
2) In your module

Code: Select all

$sql = 'SELECT ID,DATA
	FROM ' . YOUR_TABLE;
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result))
{			
	$template->assign_block_vars('DB_DATA', array(
	    'ID'			=> $row['ID'],
	    'DATA'		        => $row['DATA'],
	));
}
$db->sql_freeresult($result);
Extensions to prevent spam registrations and comments https://cleantalk.org.

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 5 guests