Page 1 of 1

[Solved] 'undefined function smarty_cms_function_anchor' when printing

Posted: Sat Sep 04, 2010 3:51 pm
by Joppybt
I have created a user defined tag {gototop} to embed multiple links to the top of a page.

Code: Select all

echo '<span style="float:right; margin-top:0.5em;">';
echo smarty_cms_function_anchor(array('anchor' => 'main','text' => '^ Top'), $this);
echo '</span>';
This has worked fine with older versions (1.6.xx) but has problems when printing after upgrading recently to 1.8.2.

You can see the result at this page (as you can see I pretty much use only default templates and modules).

When you press the Print button the page is empty and the Apache log shows:

Code: Select all

PHP Fatal error:  Call to undefined function smarty_cms_function_anchor() in /sites/furix.com/www/lib/content.functions.php(976) : eval()'d code on line 2
When I comment out the line with smarty_cms_function_anchor printing works fine (but without the links of course).

Why is smarty_cms_function_anchor not defined when printing?

(Come to think of it: actually the links are unnecessary when printing, how do I implement an 'if (not printing)' clause?)

Re: 'undefined function smarty_cms_function_anchor' when printing

Posted: Mon Sep 06, 2010 4:35 pm
by NaN
Try to check if the function exists and if not, include the plugin file.
Example:

Code: Select all


if(!function_exists('smarty_cms_function_anchor')) {
	global $gCms;
	require_once(cms_join_path($gCms->config['root_path'], 'plugins', 'function.anchor.php'));
}
echo '<span style="float:right; margin-top:0.5em;">';
echo smarty_cms_function_anchor(array('anchor' => 'main','text' => '^ Top'), $this);
echo '</span>';


Since you don't need the top links in a print output you can also just print out the top link if the function exists:

Code: Select all


if(function_exists('smarty_cms_function_anchor')) {
	echo '<span style="float:right; margin-top:0.5em;">';
	echo smarty_cms_function_anchor(array('anchor' => 'main','text' => '^ Top'), $this);
	echo '</span>';
}

Hope that helps.

[Solved] Re: 'undefined function smarty_cms_function_anchor' when printing

Posted: Mon Sep 06, 2010 5:18 pm
by Joppybt
Thank, your second option works fine for me.

Still a bit strange it is undefined but I can live with that.