Hello,
I try to use the function preprocess_pag in template.php but I get a fatal error:


function fusion_core_preprocess_page(&$variables) {
  if ($variables['node']->type == "house") {
    $variables['template_files'][] = 'page-node-house';
  }
} (-->line 532)

Fatal error: Cannot redeclare fusion_core_preprocess_page() (previously declared in /www/sites/all/themes/fusion/fusion_core/template.php:29) in www/sites/all/themes/fusion/fusion_core/template.php on line 532

Any idea why I get this error? Thanks :)

Comments

jeremycaldwell’s picture

Are you defining "function fusion_core_preprocess_page(&$variables) {" yourself or modifying the call to that function that already exists in the Fusion Core template.php file? It sounds like you are adding it rather than modifying the existing page preprocess.

Do a search in your template.php and see how many times "function fusion_core_preprocess_page(&$variables) {" appears. If it appears more than once then you need to merge your changes with the other.

jeremycaldwell’s picture

One more thing, if you are creating sub-theme of Fusion Core you can define the "function fusion_core_preprocess_page(&$variables) {" as something different and in your sub-theme's template.php.

Just change "function fusion_core_preprocess_page(&$variables) {" to "function YOURTHEME_preprocess_page(&$variables) {" where "YOURTHEME" is the name of your theme.

junro’s picture

Are you defining "function fusion_core_preprocess_page(&$variables) {" yourself
yes, so I had it twice. I'm going to change that.

if you are creating sub-theme of Fusion Core
I'm using Acquia Marina theme.

The problem is there is no template.php by default in this theme.
So I created one, and added aquia_marina_preprocess_page function but it doesn't work.
I think the template.php is not loaded, not take into account.

I was thinking I could use the template.php of core fusion, but apparently it's not the good decision.

jeremycaldwell’s picture

You're on the right track with the template.php. Since the Acquia Marina theme did not come with a template.php you needed to create one. This works along with the one provided by Fusion Core and the idea is you want to include all your custom changes and that sort of thing outside of Fusion Core. So no touching Fusion Core :)

Now that you have the template.php created and the function, try going to your Performance page and clearing the site cache. That will reload the theme files and pick up the template.php and the function within it.

junro’s picture

Thanks for your help, but it still doesn't work.

I add this im my acquia marina template file:

function aquia_marina_preprocess_page(&$variables) {
  if ($variables['node']->type == "travels") {
    $variables['template_files'][] = 'travels.tpl.php';
  }
}

For testing, my travels.tpl.php is empty in order to have a blank page, and to know if it's working...

The only way I can use template files for now is adding code in my page.tpl.php:

 if($node->type == 'travels'&&arg(2)!="edit"&&arg(2)!="delete") {
    include 'travels.tpl.php';
    return; }

but in fact, I would like to have a template for the edit page of the node type, and in all post I read, the code should be in the template.tpl.php file.

I was hopping to use the code below in page.tpl.php to custom the edit page but it doesn't work:

 if($node->type == 'travels'&&arg(2)=="edit"&&arg(2)!="delete") {
    include 'travels-edit.tpl.php';
    return; }
junro’s picture

Sorry, but this code in page.tpl.php works after running cron, it's weird, doesn't it? Flush all caches didn't do anything...

 if($node->type == 'travels'&&arg(2)=="edit"&&arg(2)!="delete") {
    include 'travels-edit.tpl.php';
    return; }
jeremycaldwell’s picture

Status: Active » Fixed

Interesting that it works after running CRON but didn't work after clearing cache.. oh well, glad you got it working! And thanks for posting up the code too.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.