Dialogs Framework Basic Concepts

Embedding php in List Templates

Updated: 21 Apr 2023


Simple, one-line php statements may be included in List Template fields by simply encasing the statement in SHORT php tags (less than followed by a question mark). An advanced technique allows Developers to embed more complex php scripting is also available.

Dialogs List Templates allow the developer to extend core functionality by invoking the power of most php statements. This flexibility allows for such tasks as calling a php function to format text or conduct a logical IF test to determine content to be displayed. Here's an example of embedding php code to format content within an item detail field:


<tr>
<td>$row[item_name] $row[code] $row[size]</td>
<td>$row[quantity]</td>
<td>@<? format_money($row[price_each],true,true)?></td>
<td><? format_money($row[line_subtotal],true,true)?></td>
</tr>

Simple if then else clauses can be implemented in-line using the alternative syntax php offers for control structures. This syntax takes the form of ((conditional test)?"output if true":"output if false"). An example that tests a _GET variable to determine if it's = the current row item_name, and if it is, adds "class=current" to a tag:


<li class="$row[css_class]"><a href="/features/$row[phantom_page]"
 <? ((($_GET[context]==$row[item_name]) || ($row[item_name]==$this->phantom_row[item_name]))?' 
class= "current"':'') ?>> $row[item_name]</a></li>

Search the Dialogs Sandbox (https://www.dialogs.com/framework_sandbox.html) for more examples. A good search term would be "<?" for any embedded php, and "((" for examples of embedded conditionals.

The reason only single php statements may be embedded in this manner is because, by default, each field of a List Template is eval'd as a single php statement. Often, the developer needs to deploy multiple lines of php code. In this instance, the advanced method should be used. The advanced method may be used by one or more fields in a Dialogs Template. It involves concatinating/assigning content to be presented to a variable, typically $html. The presence of this concatination/assignment triggers Dialogs treatment of the field as advanced, and opens the door for multi-line php coding. This is best understood by example:


$html.='<tr class="bg_$odd_even" valign="top">';

if($this->authenticated){
     $html .='<td><a href="/basic_concepts_detail.html?item_id='.$row[item_id].
                  '&item_name='.urlencode($row[item_name]).'">'.$row[item_name].'</a></td>';
}else{
     $html .='<td><strong>'. $row[item_name] .'</strong></td>';
}
$html .="<td>$row[Summary]</td>";

$html .="<td >". reformat_date('j M Y',$row[modified])."</td></tr>";
$html .='<tr><td></td><td colspan="2" style="  
                background-image: url(/imgD/bkg_content_border_light.gif);"></td></tr>';

Most fields in the Dialogs List template can accommodate the advanced technique, and most fields are triggered by the assignment of the variable $html. The exceptions are the Where clause that is triggered by $KD_list_where, Limit triggerd by $this->list_per_page_limit, and Sort triggered by $KDlist_sort. Hover over the field name while editing a List Template to verify the appropriate variable that triggers the advanced technique for that particular field.

Search the Dialogs Sandbox (https://www.dialogs.com/framework_sandbox.html) for more examples. A good search terms would be "$html" , "$KD_list_where", "$this->list_per_page_limit", or "$KDlist_sort".

LinkedInFacebookYouTubeTwitter