Jump to content

Smarty within addon


Sp0tteh

Recommended Posts

Hey,

 

In the process of creating an addon. However I really don't enjoy having to echo my html and would rather be able to split up the design from the PHP.

 

Is there a way I can use smarty and create a template file that then renders my page as well as the rest of the Admin area (header / footer ect)???

 

Cheers

Link to comment
Share on other sites

Not sure if it works with addon modules or not, but you can try returning the template array from the _output() function.

 

return array(
   'templatefile'=>'sometemplate',
   'breadcrumb'=>'',
   'vars'=> array(
       'somevar' => $somevalue,
       'somevar2' => $someothervalue));

 

This works with things like server modules.

Link to comment
Share on other sites

  • 7 months later...
Hey,

 

In the process of creating an addon. However I really don't enjoy having to echo my html and would rather be able to split up the design from the PHP.

 

Is there a way I can use smarty and create a template file that then renders my page as well as the rest of the Admin area (header / footer ect)???

 

Cheers

 

I couldnt find anything on this either, but I figured it out. If you want to use smarty templates for the add-on pages within WHMCS admin area use this code in your functions instead of putting your admin HTML code into the module and doing an echo/print of it.

 

// create object

$smarty = new Smarty;

 

// Example assign variable

$smarty->assign('name', 'george smith');

 

$smarty->caching = false;

 

$smarty->compile_dir = $GLOBALS['templates_compiledir'];

 

// display file from template folder within add-on folder

$smarty->display(dirname(__FILE__) . '/templates/template-file.tpl');

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated