• Resolved Insomnia88

    (@insomnia88)


    Hi, I created a custom widget using your docs. The widget is appearing correctly on your widget overview and on the edit page. I can also configure the form inside it (I used your hello world example and just renamed it). The problem is that the content doesn’t appear at the preview/published site. I have the feeling that maybe my template file isn’t found. I used both options: The preset tree (a tpl folder including a *.php file) and by defining it through

    get_template_name

    .
    Is there any way to test/debug where the problem is?

    My main widget file:

    
    /*
    Widget Name: divider widget
    Description: An example widget which displays 'Hello world!'.
    Author: Me
    Author URI: https://example.com
    Widget URI: https://example.com/hello-world-widget-docs,
    Video URI: https://example.com/hello-world-widget-video
    */
    
    class Divider_Widget extends SiteOrigin_Widget {
    
        function __construct() {
            parent::__construct(
                'divider-widget',
                'divider widget',
                array(
                    'description' => 'A hello world widget',
                    'help'        => 'https://example.com/hello-world-widget-docs',
                ),
                array(
                ),
                array(
                    'text' => array(
                        'type' => 'text',
                        'label' => 'Hello world! goes here',
                        'default' => 'Hello world!'
                    ),
                ),
                plugin_dir_path(__FILE__)
            );
        }
        
        function get_template_name($instance) {
            return 'divider-widget-template.php';
        }
    }
    
    siteorigin_widget_register('divider-widget', __FILE__, 'Divider_Widget');
    
    function my_awesome_widget_banner_img_src( $banner_url, $widget_meta ) {
        if( $widget_meta['ID'] == 'divider-widget') {
            $banner_url = get_theme_file_uri().'/inc/custom-widgets/divider-widget/assets/banner.svg';
        }
        return $banner_url;
    }
    add_filter( 'siteorigin_widgets_widget_banner', 'my_awesome_widget_banner_img_src', 10, 2);

    and my tpl:

    <div>
    test
        <?php echo wp_kses_post($instance['text']) ?>
    </div>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor alexgso

    (@alexgso)

    Hi insomnia88,

    I suspect the issue is that you’ve included the extension – we append .php automatically. Try replacing:

    return 'divider-widget-template.php';

    With:

    return 'divider-widget-template';

    If that doesn’t help, please open so-widgets-bundle/base/siteorigin-widget.class.php and replace:

    @ include $template_file;

    Change to:

    include $template_file;

    You should now see any potential error messages related to the template not including.

    Thread Starter Insomnia88

    (@insomnia88)

    Thanks for your fast response.

    You were right, it was just the .php extension at the template name. I am ashamed that I havn’t noticed it myself.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom widget not showing content’ is closed to new replies.