I have just created my own module and need a bit of help displaying the content on the front end. I currently have some template tags {exp:address_book:contact}{/exp:address_book:contact}
and within them a series of variables; {ab_name}
, {ab_contact_number}
etc.
These are laid out in the site templates as so:
{exp:address_book:contacts}
<table class="contact_info">
<tr>
<td class="label">Title</td>
<td>{ab_title}</td>
<td class="label">Company</td>
<td>{ab_company}</td>
</tr>
<tr>
<td class="label">Name</td>
<td>{ab_first_name} {ab_last_name}</td>
<td>Company Tel No.</td>
<td>{ab_company_contact_number}</td>
</tr>
<tr>
<td class="label">Contact No.</td>
<td>{ab_personal_number}</td>
<td colspan="2">{ab_address_1}</td>
</tr>
<tr>
<td class="label">Email</td>
<td><a href="mailto:{ab_email}">{ab_email}</a></td>
<td colspan="2">{ab_address_2}</td>
</tr>
<tr>
<td class="label">Facebook</td>
<td><a href="{ab_facebook}" target="_blank">View page</a></td>
<td colspan="2">{ab_city}</td>
</tr>
<tr>
<td class="label">Twitter</td>
<td><a href="{ab_twitter}" target="_blank">View feed</a></td>
<td colspan="2">{ab_county}{if ab_country}, {ab_country}{/if}</td>
</tr>
<tr>
<td class="label">LinkedIn</td>
<td><a href="{ab_linkedin}" target="_blank">View profile</a>
<td colspan="2">{ab_post_code}</td>
</tr>
</table>
{/exp:address_book:contacts}
Ideally I need to find a way to output this data in a single tag, rather than having to specify the layout in the site template files. Is there any way to do this?
Here is my function in my mod.module.php file:
public function contacts()
{
$contact_id = $this->EE->TMPL->fetch_param('contact_id');
$tagdata = $this->EE->TMPL->tagdata;
$this->EE->db->select('*');
if( $contact_id ) {
$this->EE->db->where('id', $contact_id);
}
$this->EE->db->from('address_book');
$this->EE->db->order_by('first_name', 'asc');
$query = $this->EE->db->get();
if ($query->num_rows() == 0)
{
return $this->EE->TMPL->no_results();
}
foreach ( $query->result_array() as $row ) {
$variables[] = array(
'ab_title' => $row['title'],
'ab_first_name' => $row['first_name'],
'ab_last_name' => $row['last_name'],
'ab_personal_number' => $row['personal_contact_number'],
'ab_company' => $row['company'],
'ab_company_contact_number' => $row['company_contact_number'],
'ab_address_1' => $row['address_street_1'],
'ab_address_2' => $row['address_street_2'],
'ab_city' => $row['address_city'],
'ab_county' => $row['address_county'],
'ab_country' => $row['address_country'],
'ab_post_code' => $row['address_post_code'],
'ab_website' => $row['website'],
'ab_email' => $row['email_address'],
'ab_facebook' => $row['facebook'],
'ab_twitter' => $row['twitter'],
'ab_linkedin' => $row['linkedin'],
);
}
return $this->EE->TMPL->parse_variables( $tagdata, $variables );
}
Any help would be greatly appreciated, thank you.