We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Template library ’breaking’ on second call

Development and Programming

James Chambers's avatar
James Chambers
7 posts
15 years ago
James Chambers's avatar James Chambers

Hello all,

I’ve got two custom plugins being called on the same page, both of which use the template library to parse a template (as outlined by Derek Jones here). I’m using it like so:

Plugin code (effectively the same in both plugins):

$view_data = array('some', 'array');
$this->EE->load->library('Template', NULL, 'TMPL');
$this->EE->TMPL->fetch_and_parse('shared', '_template_name_here');
$content = $this->EE->TMPL->parse_globals($this->EE->TMPL->final_template);
$this->EE->TMPL->parse_variables_row($content, $view_data);

Template

{exp:plugin_one}
{exp:plugin_two}

Plugin one renders with no problems, but when it gets to the line

$this->EE->load->library('Template', NULL, 'TMPL');

in plugin two, things stop parsing. I assume it’s something to do with the library being loaded twice?

Any help very gratefully received!

Moved to Development and Programming by Moderator

James

       
Sue Crocker's avatar
Sue Crocker
26,054 posts
15 years ago
Sue Crocker's avatar Sue Crocker

Hi, James. Welcome to the ExpressionEngine forums!

Since this appears to be a coding issue, moving to the Development forum for additional community support.

       
James Chambers's avatar
James Chambers
7 posts
15 years ago
James Chambers's avatar James Chambers

Sorry for the bump, but does anyone have an idea about how I could solve this?

Thanks very much,

James

       
Rob Sanchez's avatar
Rob Sanchez
335 posts
15 years ago
Rob Sanchez's avatar Rob Sanchez

You could try instantiating the library yourself in the local scope:

$view_data = array('some', 'array');
$TMPL = new EE_Template;
$TMPL->fetch_and_parse('shared', '_template_name_here');
$content = $TMPL->parse_globals($TMPL->final_template);
$TMPL->parse_variables_row($content, $view_data);
       
James Chambers's avatar
James Chambers
7 posts
15 years ago
James Chambers's avatar James Chambers

Thanks Rob, that worked a treat!

James

       
medium's avatar
medium
5 posts
14 years ago
medium's avatar medium

Hi all,

I’m trying to do a very similar thing to James, and having been using Rob’s solution to do it.

However - if I try and parse a template with an embed tag in it (i.e. {embed="group/template}) it just outputs a message that says ‘You have caused a template loop due to improperly nested sub-templates’.

Also… if I have an {exp:channel:entries} tag pair in there, nothing is output from within that pair. Truning on error reporting shows me the following error:


A PHP Error was encountered

Severity: Notice

Message: Undefined property: EE::$TMPL

Filename: channel/mod.channel.php

Line Number: 221 Fatal error: Call to a member function fetch_param() on a non-object in /Users/markp/Dropbox/Mark/Medium/Clients/DOGWF_Dogwoof_Films/_sites/goodwithfilm.com/httpdocs/admin/expressionengine/modules/channel/mod.channel.php on line 221


Anyone have any ideas what may be causing this? Any help would be greatly appreciated!!

Cheers,

Mark

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.