Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By high1memo on
Hi All,
in administer>>blocks, I added a new block, and gave it the following PHP code:
CreateImageLink('home', 'Home');
CreateImageLink('briefbio', 'Brief Bio');
CreateImageLink('history', 'History');
CreateImageLink('storysofar', 'The Story So Far');
CreateImageLink('bicentenary', 'The Bicentenary Concert');
CreateImageLink('plaque', 'Plaque');
CreateImageLink('trust', 'The Emidy Trust');
CreateImageLink('archive', 'The Emidy Archive');
CreateImageLink('links', 'Links');
CreateImageLink is a PHP function I defined at the top of my page.tpl.php
function CreateImageLink($url, $alt) {
print "<a href='/$url' onmouseout='MM_swapImgRestore();' onmouseover='MM_swapImage('$url','','$url"."_f2.jpg',1);'><img name='$url' src='$url.jpg' id='$url' alt='$alt' /></a>";
}
?>
I thought this should work. Now when I goto my site I get
Fatal error: Call to undefined function: createimagelink() in /home/josephan/www/www/includes/common.inc(1158) : eval()'d code on line 2
So I cant even goto the blocks section to remove the code! Is there any way to fix this? Or do I have to manually go and edit the database to get rid of it?
So Can we not call custom PHP functions from a block? if so what is the procedure?
Comments
you might want to try
you might want to try defining the function in a .inc file instead and including that file in to your template instead. I've heard of this fixing the same issue for folk who tried to define functions in the body of the page.
If you make this change, you shouldn't need to make any db changes.
When the block is executed, no theme('page') yet
The block code is executed before the first call to theme (and certainly before the call to theme('page')). Whether the function is defined in page.tpl.php or in an include file doesn't matter; it won't be loaded at the time the function is called.
--
The Manual | Troubleshooting FAQ | Tips for posting | Make Backups! | Consider creating a Test site.
So define the function
in settings.php
Thomas Narres
Keep the sunny side up
Then she could put the
Then she could put the include at the top of the block
module
To repair the current installation, either edit the block in the table 'boxes' or set its status to 0 in the blocks table (you have to do this for the theme you use).
Put the function in a module, enable it and it will be available to your blocks & nodes. You can also make a module that defines the block
--
The Manual | Troubleshooting FAQ | Tips for posting | Make Backups! | Consider creating a Test site.
hurrah!
Actually, immediately after posting this, I hada look at the database, and found the blocks table, and set the status of my block to 0. So now I can at least visit the site.
And just now I tried defining the function in settings.php as suggested and it works perfectly!
Thanks all!
actually,
When I said it works perfectly, I meant the function is defined and the block is displaying correctly - according to the PHP function. It just so happens that that PHP function is buggy and the rollover code doesnt work... so if a noncoder stumbles upon this thread and wanted to use the same function he will have troubles. So here is the correct version:
(replace /themes/bluemarine/ with the path to your button images)
and in your page.tpl.php add this in the head: