How to display the available tickets information on the event page
Changing the layout or adding extra information regarding your created events is done through template overrides. This process is explained in detail here
In this article we will present how to create a template override that displays the details of the tickets available for an event. The file that controls the event details page layout is the show.php located in the components\com_rseventspro\views\rseventspro\tmpl. The steps that you need to take are:
- go to the templates folder of your Joomla! installation;
- access the html folder of your currently used template;
- create a new folder in the html folder named com_rseventspro;
- in the com_rseventspro folder create an additional folder named rseventspro;
- copy the show.php file from components\com_rseventspro\views\rseventspro\tmpl into templates\your_template_name\html\com_rseventspro\rseventspro.
Now we have all that we need in order to start generating the template override. Please open the show.php file from the template folder and add the following code:
<?php $db = Joomla\CMS\Factory::getDBO(); $db->setQuery("SELECT * FROM #__rseventspro_tickets WHERE ide = '".$event->id."'"); $tickets = $db->loadObjectList(); if($tickets) { $t = '<h4>This event has the following tickets:</h4>'; $t .='<table style="text-align: center;">'; $t .='<tr>'; $t .='<th style="color: blue;">Ticket Name</th>'; $t .='<th style="color: blue;">Ticket Price</th>'; $t .='<th style="color: blue;">Number of seats</th>'; $t .='</tr>'; foreach($tickets as $ticket) { $t .='<tr>'; $t .='<td>'.$ticket->name.'</td>'; $t .='<td>'.rseventsproHelper::currency($ticket->price).'</td>'; $t .='<td>'.$ticket->seats.'</td>'; $t .= '</tr>'; } $t .='</table>'; echo $t; } ?>
This will create a simple table with all the tickets available for your event. Next we will explain the code. The code can be added at any point in your file, depending on where you want this information to be displayed. The first part of the code:
$db = Joomla\CMS\Factory::getDBO(); $db->setQuery("SELECT * FROM #__rseventspro_tickets WHERE ide = '".$event->id."'"); $tickets = $db->loadObjectList(); if($tickets) {
performs a database query that will retrieve all the ticket details from the #__rseventspro_tickets table base on the event id and stores them in the $tickets variable. The if clause is used in order to display the table only when the event has tickets defined, if an event does not have tickets then the table will not be shown. The next section of code:
$t = '<h4>This event has the following tickets:</h4>'; $t .='<table style="text-align: center;">'; $t .='<tr>'; $t .='<th style="color: blue;">Ticket Name</th>'; $t .='<th style="color: blue;">Ticket Price</th>'; $t .='<th style="color: blue;">Number of seats</th>'; $t .='</tr>';
...generates the static part of the table: the header informing what will be displayed next and the table headers. After this is added we will need to display the information that was retrieved from the database. This is done through the following code:
foreach($tickets as $ticket) { $t .='<tr>'; $t .='<td>'.$ticket->name.'</td>'; $t .='<td>'.rseventsproHelper::currency($ticket->price).'</td>'; $t .='<td>'.$ticket->seats.'</td>'; $t .= '</tr>'; }
The last section of the code is used to close the table tag in order to make sure that the page has a correct HTML syntax:
$t .='</table>'; echo $t; }
3 persons found this article helpful.
You Should Also Read
How to display a message when the event is full |
How to allow event owners to sell their own tickets |
How to remove the time the events occur on from the events listing |