GaryJones / Gamajo-Template-Loader

A class to copy into your WordPress plugin, to allow loading template parts with fallback through the child theme > parent theme > plugin.
GNU General Public License v2.0
292 stars 61 forks source link

Use template loader object within template #41

Closed wetory closed 3 years ago

wetory commented 3 years ago

Hello is it possible to use template loader inside template that is called within get_template_part function? For example, template for table which iterates data and load row template for every item. Thank you in advance.

GaryJones commented 3 years ago

It's fairly simple code, and ultimately, just a basic class.

I've not tried it, but I think that each template lookup is done independently of any other, so the effort to nest these lookups should work - but please try and let me know!

alanef commented 2 years ago

@wetory yes - I do this all the time

$template_loader = new Template_Loader();
$template_loader->set_template_data(
    array(
        'template_loader' => $template_loader,
        // and what ever
    )
);

then in the template you can use

$data->template_loader->get_template_part( 'whatever');

Works fine