1

I built an extension which works fine and I'm trying to make it work in my template but I don't know how to do and actually, I don't even know if it could work.

My code looks like:

class Easypost_extension_ext

{

    public $name        = 'Easypost extensions';
    public $version     = '1.0.0';
    public $description = 'Display shipment only if there is a product to send';
    public $docs_url    = 'https://ellislab.com/expressionengine/user-guide/';
    public $settings_exist = 'n';
    public $settings    = array();
    private $EE;
    private $apikey;

My function is called check_shipping and I'm trying to call it in my template in this way:

<select class="form-control" id="easypost" name="easypost">
    {exp:easypost_extention:check_shipping}
    <option value="">
        {service}
        {days}
        {rate}
        {currency}
        {rateid}
    </option>
    {/exp:easypost_extention:check_shipping}
</select>

But I receive an error in my template. Is there any way to fix my problem?

1 Answer 1

2

You cannot use ext to call in template as plugin. You must have to create mod.easypost_extention.php file for that. Use this code inside that file.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Easypost_extension
{
    public function __construct()
    {

    }

    function check_shipping()
    {

        $tagdata    = ee()->TMPL->tagdata;
        $tagparams  = ee()->TMPL->tagparams;

        // Some code


        return ee()->TMPL->parse_variables_row($tagdata, $myArrayToParse);
    }
}

You can gain more information from here. https://docs.expressionengine.com/latest/development/plugins.html

2
  • Thanks! What's the difference between tagdata and tagparams? Apr 3, 2018 at 13:00
  • 1
    you will get everything written between {exp:your:plugin} {/exp:your:plugin} in tagdata. In tagparams you will get array of each and every parameters you passed in your loop: {exp:plugin data="abc" entry="12" etc.} Apr 3, 2018 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.