How to create a snapin

aarondwyer

New Member
Hi

Is there any documentation on how to go about making a snapin?

I've modeled off the existing ones in the snapin folder. But I'm not sure how to do it properly.

I would like to have it show up in the menu under "Accounts" / "Packages"

Aaron
 
We don't really have any docs for this yet.

You should be able to call:

Code:
$this->addMappingForTopMenu('admin', 'clients', 'templateName', 'title', 'desc');

Then make sure you have a function called templateName() in your Snapin, as well as a templateName.phtml in the snapin directory, and that will be the view that is used.

Once you activate the snapin and enable the permissions, log out of CE and back in to force it to re-load the menu.
 
Ok I now have a link in the menu. Thank you for that.

I have generated the content that I want to show in the view() function.

How do I get content from the view function to show inside CE?

Code:
function view()
{
    $output = '<h3>Snapin Output</h3>';

    return $this->view->render('snapinname.phtml');
}

In the snapinname.phtml file do I just put this to show the content?

Code:
<?php echo $output; ?>

Aaron
 
You don't need to do any HTML in the function. Just have a view.phtml in the directory and it'll render that HTML. If you need to pass any variables, just set them in $this->view->varName in that function.
 
Hi Matt

Sorry but I don't seem to be able to work it out. I can't get the output from the script into the view.phtml file and onto the screen.

I have attached a basic snapin example where I'm looking to get a link in the menu (which works) and then get some content to get to the screen in CE.

I'm probably missing something very basic. Any ideas?

I can reach the snapin page from a linked menu item like this...

CEinstall/admin/index.php?fuse=admin&view=viewsnapin&controller=snapins&plugin=snapinexample&h=dG9wbWVudTow

Aaron
 

Attachments

  • snapinexample.zip
    958 bytes · Views: 8
Last edited:
Since you're calling snapinexample in the addMappingForTopMenu, that is the function and view name that'll be returned.

Just add any PHP code to the snapinexample function, and any HTML to snapinexample.phtml and you should be good
 
Ok thanks, I've tried that, and still not getting the PHP parsed into the CE view. Sorry but I must be missing something simple here. Seems fairly straight forward a concept. Any ideas?

I only have 2 files in my snapinexample now.

This is my snapinexample.phtml

Code:
Snapin Example on snapinexample.phtml
<br>
<?php echo $output; ?>
<br>
{END}

This is my PluginSnapinexample.php

Code:
<?php
require_once 'modules/admin/models/SnapinPlugin.php';

class PluginSnapinexample extends SnapinPlugin
{
    public function getVariables()
    {
        $variables = [
            lang('Plugin Name')       => [
                'type'        => 'hidden',
                'description' => 'Snapin Example Description',
                'value'       => 'Snapin Example',
            ]
        ];
        
        return $variables;
    }

    function init()
    {
        $this->setDescription("This is a snapin example description.");
        $this->setPermissionLocation("clients");
        $this->addMappingForTopMenu("admin","clients","snapinexample","Snapin Example Menu","Snapin Example Description Menu");
    }

    function snapinexample()
    {
        $output = '<h3>Snapin Example from snapinexample PHP</h3>';
    
        return $output;
    }
        
}
?>
 
Ah, sorry!

Code:
Snapin Example on snapinexample.phtml
<br>
<?php echo $this->output; ?>
<br>

Code:
function snapinexample()
{
    $this->view->output = '<h3>Snapin Example from snapinexample PHP</h3>';    
}

That should work for you now.
 
Hello
Ah, sorry!

Code:
Snapin Example on snapinexample.phtml
<br>
<?php echo $this->output; ?>
<br>

Code:
function snapinexample()
{
    $this->view->output = '<h3>Snapin Example from snapinexample PHP</h3>';   
}

That should work for you now.
Could you tell me how can I include a HTML file here ?
Thanks
 
The function name that is called for the view (snapinexample) will look for snapinexample.phtml.
 
Consider we submit form in view.phtml
so we can now$_GET['v']==process in view.phtml function.
How can I render a new page, for example, secondpage.phtml ?
 
Finally getting back to sorting this out and stuck on this again.

I've noticed that inline HTML elements in the PHP function are not being parsed in the PHTML and shown as straight text on the output.

For example


Code:
Snapin Example on snapinexample.phtml
<br>
<?php echo $this->output; ?>
<br>


Code:
function snapinexample()
{
$this->view->output = '<h3>Snapin Example from snapinexample PHP</h3>'; 
}

Produces an output on the screen with the HTML tags as straight text instead of being read as HTML

<h3>Snapin Example from snapinexample PHP</h3>


How do we set HTML tags in the PHP which get parsed in the PHTML view?
 
All variables are run through an HTML escaper. You can either do the HTML in the phtml file (which is recommended) or if you have to have HTML in a variable, call $this->unescape($this->output);
 
All variables are run through an HTML escaper. You can either do the HTML in the phtml file (which is recommended) or if you have to have HTML in a variable, call $this->unescape($this->output);
Nicely answered CE-Matt.
 
@Matt

I have two question about snapin
I have created a snapin under billing menu ( client area )

$this->addMappingForTopMenu('public', 'billing', 'view', 'Bank Receipt', 'Integrate Bank Receipt in ClientPortal Billing');

1) How can I make it public without needing to login ?
currently clients need to login to see this menu item.
1638514402451.png

2) if I decided to make it public in main page with below command how can I place icon for it ?
$this->addMappingForTopMenu

1638514335578.png


Thanks
 
Last edited:
To display the snap-in box with fontawesome icon:

$this->addMappingForPublicMain("view", "Snapin Title", 'Integrate in Public Home', 'fas fa-invoice');

or add this to the $variables of the snap-in to display the png image

'Use Image' => array(
'type' => 'hidden',
'value' => '1'
)
 
Back
Top