[Solved] 'undefined function smarty_cms_function_anchor' when printing

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
Joppybt
New Member
New Member
Posts: 6
Joined: Fri Aug 22, 2008 11:47 am

[Solved] 'undefined function smarty_cms_function_anchor' when printing

Post 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?)
Last edited by Joppybt on Mon Sep 06, 2010 5:19 pm, edited 1 time in total.
NaN

Re: 'undefined function smarty_cms_function_anchor' when printing

Post 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.
Joppybt
New Member
New Member
Posts: 6
Joined: Fri Aug 22, 2008 11:47 am

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

Post by Joppybt »

Thank, your second option works fine for me.

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

Return to “CMSMS Core”