smarty $view no longer available
-
- Regular
- Posts: 3652
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
smarty $view no longer available
I just noticed that logic I use in a template to determine the value of $view was no longer working.... when I set {debug} in entries.tpl, $view isn't listed as one of the smarty variables. This is with the latest 1.3 branch.
Doesn't appear to be my template either - also tried it with carl_contest - same thing - no $view.
Doesn't appear to be my template either - also tried it with carl_contest - same thing - no $view.
=Don=
-
- Regular
- Posts: 3652
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
You mean when you disable microformats, $view gets in again?
I don't see anything in the 'genpage' hook of microformats that would even touch this variable. You are using the recent version in spartacus, not some other version?
Regards,
Garvin
You mean when you disable microformats, $view gets in again?
I don't see anything in the 'genpage' hook of microformats that would even touch this variable. You are using the recent version in spartacus, not some other version?
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
- Regular
- Posts: 3652
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
Hm, can you edit the plugin and insert a simple "return true;" just as the first line after the "case 'genpage':" case? This could show whether the genpage hook is responsible,or another one.
I'll be offline for the weekend, so I'll have to get backto you next week.
Regards,
Garvin
Hm, can you edit the plugin and insert a simple "return true;" just as the first line after the "case 'genpage':" case? This could show whether the genpage hook is responsible,or another one.
I'll be offline for the weekend, so I'll have to get backto you next week.
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Don, let me know it it's got anything to do with the microformats plugin. I have begun to rewrite the plugin a couple of months ago, but never found the motivation to finish it
Now, after I received a copy of Garvin's excellent S9y book, I am determined to delve into the depths of my plugin again Right now, however, I'm busy tweaking some options in my blog that I've just found out exist. S9y book FTW!!
- Mattsches
Now, after I received a copy of Garvin's excellent S9y book, I am determined to delve into the depths of my plugin again Right now, however, I'm busy tweaking some options in my blog that I've just found out exist. S9y book FTW!!
- Mattsches
-
- Regular
- Posts: 3652
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
Garvin, at line 199 I added return true, and $view is again available.garvinhicking wrote:Hi!
Hm, can you edit the plugin and insert a simple "return true;" just as the first line after the "case 'genpage':" case? This could show whether the genpage hook is responsible,or another one.
I'll be offline for the weekend, so I'll have to get backto you next week.
Regards,
Garvin
Code: Select all
case 'genpage':
return true;
=Don=
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
And if you move that return true after the line where serendipity_smarty_init() is called? Maybe that function call somehow resets the view...
Regards,
Garvin
And if you move that return true after the line where serendipity_smarty_init() is called? Maybe that function call somehow resets the view...
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
- Regular
- Posts: 3652
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
That is too strange, because the serendipity_smarty_init() call does not tamper with $serendipity['view'].
Is your template using a config.inc.php? That file will then be utilized, maybe that could be responsible. If you use it, please temporarily remove that config.inc.php file?
Regards,
Garvin
That is too strange, because the serendipity_smarty_init() call does not tamper with $serendipity['view'].
Is your template using a config.inc.php? That file will then be utilized, maybe that could be responsible. If you use it, please temporarily remove that config.inc.php file?
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
- Regular
- Posts: 3652
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
Yup, the microformats plugin is causing it.
The problem starts in include/genpage.inc.php, line 221. First we call the genpage hook, then we call serendipity_smarty_init(). This is where $view gets set; it's among the variables passed to serendipity_smarty_init() to be assigned to Smarty.
Unfortunately, the microformats plugin calls serendipity_smarty_init() with no assignable variables. (Other plugins may do this, too; I don't mean to single out microformats.) When we return to genpage.inc.php after the genpage hook, we call serendipity_smarty_init() with the set of variables to be assigned (including $view), but serendipity_smarty_init() sees that it's already initialized once, and skips the variable assignments.
By Garvin's great foresight, we pass the list of variables to initialize with the genpage hook. So the right thing to do in a plugin is not to initialize Smarty and assign variables, but rather to add the necessary initializations to the $addData.
In short, I changed the microformats plugin (starting on line 199) from this:
To this:
When the genpage hook is done, all that additional data should be added to the list of things that get assigned when Smarty is initialized. Tested only to verify that nothing blows up; commited; should be available withing 24 hours through SPARTACUS.
Morals of the story:
The problem starts in include/genpage.inc.php, line 221. First we call the genpage hook, then we call serendipity_smarty_init(). This is where $view gets set; it's among the variables passed to serendipity_smarty_init() to be assigned to Smarty.
Unfortunately, the microformats plugin calls serendipity_smarty_init() with no assignable variables. (Other plugins may do this, too; I don't mean to single out microformats.) When we return to genpage.inc.php after the genpage hook, we call serendipity_smarty_init() with the set of variables to be assigned (including $view), but serendipity_smarty_init() sees that it's already initialized once, and skips the variable assignments.
By Garvin's great foresight, we pass the list of variables to initialize with the genpage hook. So the right thing to do in a plugin is not to initialize Smarty and assign variables, but rather to add the necessary initializations to the $addData.
In short, I changed the microformats plugin (starting on line 199) from this:
Code: Select all
case 'genpage':
include_once(dirname(__FILE__).'/smarty.inc.php');
if (!isset($serendipity['smarty'])) {
serendipity_smarty_init();
}
$serendipity['smarty']->assign('subnode', ($this->get_config('subnode') ? 1 : 0));
$serendipity['smarty']->assign('best', $this->get_config('best'));
$serendipity['smarty']->assign('step', $this->get_config('step'));
$serendipity['smarty']->assign('timezone', $this->get_config('timezone'));
$serendipity['smarty']->register_function('microformats_show', 'microformats_serendipity_show');
break;
Code: Select all
case 'genpage':
$addData['subnode'] = ($this->get_config('subnode') ? 1 : 0);
$addData['best'] = $this->get_config('best');
$addData['step'] = $this->get_config('step');
$addData['timezone'] = $this->get_config('timezone');
$addData['microformats_show'] = 'microformats_serendipity_show';
break;
Morals of the story:
- Plugins shouldn't call serendipity_smarty_init().
- Garvin has already thought of everything.
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
Thanks for that patch! Now I see the problem.
With your patch however you removed the register_function() call to a microformat function. Was this no longer necessary? Does it work without it?
Regards,
Garvin
Thanks for that patch! Now I see the problem.
With your patch however you removed the register_function() call to a microformat function. Was this no longer necessary? Does it work without it?
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Oh, bloody H. I didn't even recognize that was a different call.
Nothing blows up, and my frontpage event list still looks OK, but I'll bet the microformats don't work very well now.
Hmmm, there's no way to pass functions to register on init. Maybe Garvin didn't think of everything.
Well, the easy thing to do is just add the function during the "frontend_header" hook. By then the "genpage" hook has already been called, and Smarty is already initialized (it has to be, because frontend_header is hooked from a template). Alternatively, I could just check at each hook, and add it for the first hook that doesn't have it.
In the future, it might be nice to have a 'Smarty initialization complete' hook.
Meanwhile, I'm updating the plugin to fix my error. I'm also adding a 'path' variable (copied from the lightbox plugin), so users don't have to edit their index.tpl and insert a '<link>' tag.
Is it plugins that you need to define strings in every language, or the main code? I can never remember.
Nothing blows up, and my frontpage event list still looks OK, but I'll bet the microformats don't work very well now.
Hmmm, there's no way to pass functions to register on init. Maybe Garvin didn't think of everything.
Well, the easy thing to do is just add the function during the "frontend_header" hook. By then the "genpage" hook has already been called, and Smarty is already initialized (it has to be, because frontend_header is hooked from a template). Alternatively, I could just check at each hook, and add it for the first hook that doesn't have it.
In the future, it might be nice to have a 'Smarty initialization complete' hook.
Meanwhile, I'm updating the plugin to fix my error. I'm also adding a 'path' variable (copied from the lightbox plugin), so users don't have to edit their index.tpl and insert a '<link>' tag.
Is it plugins that you need to define strings in every language, or the main code? I can never remember.
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
One can register smarty functions any time before the smarty output is called...so frontend_header sounds like a suitable register_function call to me?!
Regards,
Garvin
One can register smarty functions any time before the smarty output is called...so frontend_header sounds like a suitable register_function call to me?!
New language constants are only required in each file of the main s9y release. They wouldn't hurt for plugins though, so you can simply try to remember "put it in everywhere", that has the least screw up factorIs it plugins that you need to define strings in every language, or the main code? I can never remember.
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/