This thread is over two years old and may be outdated. Please create a new thread if you need help, or email us if you have an active Premium license.

How to pass data in the_widget() ?

Open 1 reply developergeneral
7 years ago · Last reply by Alex S 7 years ago

Hey guys, i created a plugin as you explained in your tutorial site. Everything work fine but i want to insert the widget also in my single-pages, which i only can add in the template files.

For my project, i need to update the single-event.php file and i tried to insert the plugin via the function the_widget().
<?php the_widget(‘Event_Widget’, $instance, $args); ?>
My $instance is an array and had all variables which i also match to the tpl via get_template_variables() function.

My array in the widget file:

return array(
‘headline’ => $instance[‘layout’][‘headline’],
‘headlineSize’ => $instance[‘layout’][‘headlineSize’],
‘body’ => $instance[‘layout’][‘body’],
‘txtPos’ => $instance[‘layout’][‘position’],
‘bgColor’ => $instance[‘layout’][‘bg_color’],
‘hl_color’ => $instance[‘layout’][‘hl_color’],
‘buttonTxt’ => $instance[‘button’][‘text’],
‘event’ => $instance[‘event’][‘category’],
‘layout’ => $instance[‘event’][‘layout’],
‘order’ => $instance[‘event’][‘order’],
);

So i create a $instance with …

$instance = array(
‘headline’ => ‘My Headline’,
‘headlineSize’ => ‘h2’,
‘body’ => ‘This is the Body’,
‘txtPos’ => ‘center’,
‘bgColor’ => ‘#FFF’,
‘hl_color’ => ‘#333’,
‘buttonTxt’ => ‘My Button’,
‘event’ => ‘festival’,
‘layout’ => 2,
‘order’ => ‘asc’,
);

At the end, i see the widget but nothing of my arguments was set to the widget. My widget come with the default settings.

How do i store the $var into my widget to get the output?

Thanks a lot for help!

This is our free support forum. Replies can take several days.

Need fast email support? Get SiteOrigin Premium

Replies

1
  1. Alex S Staff 7 years, 3 months ago

    Hi Aboutsam,

    Data is passed to the widget in a similar manner as it’s structured in the widget itself. For example, if you want to pass the headline text, you’ll need to pass:

    'headline' => array(
        'text' => 'This is the headline text';
    ),

    You’ll need to pass more than that for the widget to display, but the above example PHP should give you a better idea of how to proceed.

Replies on this thread are closed.

Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Have a different question or issue?

Start New Thread