Welcome, Guest
Username: Password: Remember me
This category is read only
  • Page:
  • 1


Using PHP in JooDB templates 8 years 7 months ago #1566

  • Dirk
  • Dirk's Avatar Topic Author
  • Offline
  • Posts: 1183
  • Karma: 21
  • Thank you received: 224
A simple template engine can not fit for every requirement. If you want to output calculations you need to extend template output. There are multiple ways to do this.

1) Use a php content-plugin
We tested directPHP . Before you can use this, you make sure that your editor or jommla does not kill the PHP-code from the template. You should also be aware that such a plugin might be a security problem if your site has a public forum for example.

2) Use the plugin system (Pro only)
The pro version has a simple built in plugin system. Just create a php-file with the name of the desired command and add your output $output - variable. (see examples)

Example calculate.php
Multiply ammount with value and send it to the output.
  $output .= "Total: ".number_format(($item->ammount*$item->value), 2, ',', '');
You can now call the plugin by {joodb calculate} in your template.

3) Modify the view output
See here

Use Javascript
If you want to hide fields or modfiy the output you can also use Javascript.

Replace the text in element wit ID calculate with the total.
<script type="text/javascript" >
document.getElementById("calculate").innerHTML = {joodb field|ammount}*{joodb field|value};
The following user(s) said Thank You: rammon, MichaS., office.terraristik, jumagaru, jrg.san.martin.gmail

Please Log in or Create an account to join the conversation.

Last edit: by Dirk.
  • Page:
  • 1