Welcome to Geeklog, Anonymous Monday, December 23 2024 @ 08:39 am EST

Geeklog Forums

Using includes


Status: offline

dwl

Forum User
Junior
Registered: 01/05/11
Posts: 25
confused
Good day,

Okay...time for a question that will show what I am...a newbie. I searched the site on this topic but didn't find a complete answer or one that met my circumstances. There were some answers going back to 2006 but isn't that eons ago in relation to PHP development and evolution of this CMS?

If I want to create a php include for a div in the banner of a theme I am editing, what is the procedure? I tried the following and received an error that listed for 1500+ lines in html.
Text Formatted Code
    <div class='header-logobg-container-inner'>
        <?php include('includes/dl-logo.inc') ?>
        .....
    </div>


Thanks for taking the time to read this and have a Great day.

dwl
 Quote

Status: offline

Roccivic

Forum User
Moderator
Registered: 05/19/10
Posts: 136
I guess that you need to go through the template engine, you can't just include php in thtml files as it won't be executed.

Perhaps add a new template variable:
Text Formatted Code
    <div class='header-logobg-container-inner'>
        {mycode}
    </div>

Then find where that template is called and set the new variable:
Text Formatted Code
...
    include('includes/dl-logo.inc'); // this include file should provide a new function: getmycode()
    $template->set_var('mycode', getmycode());
 


Hope this helps.

Rouslan
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Hi,

Quote by: dwl
Text Formatted Code
    <div class='header-logobg-container-inner'>
        <?php include('includes/dl-logo.inc') ?>
        .....
    </div>



You can put php in template (but we can live without). Maybe the error was a path issue?

Text Formatted Code
include(includes/dl-logo.inc) [function.include]: failed to open stream: No such file or directory @ C:\wamp\www\geeklog-1.7.1\public_html\lib-common.php(1305) : eval()'d code line 53


You must give the full path to your file dl-logo.inc

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

Roccivic

Forum User
Moderator
Registered: 05/19/10
Posts: 136
Quote by: cordiste

You can put php in template (but we can live without). Maybe the error was a path issue?


I had no idea you could do that Smile

Quote by: cordiste

You must give the full path to your file dl-logo.inc


Perhaps it could something like this, so:
Text Formatted Code
include $_CONF['site_url'] . "pathto/dl-logo.inc";


Rouslan
 Quote

Status: offline

dwl

Forum User
Junior
Registered: 01/05/11
Posts: 25
mellow
cordiste, you were exactly right with the requirement of a full path to the include, from the root right to the end of the filename. The relative path I was trying was generating a path issue error similar to what you shared.

Quote by: cordiste

Hi,

Quote by: dwl
Text Formatted Code
    <div class='header-logobg-container-inner'>
        <?php include('includes/dl-logo.inc') ?>
        .....
    </div>



You can put php in template (but we can live without). Maybe the error was a path issue?

Text Formatted Code
include(includes/dl-logo.inc) [function.include]: failed to open stream: No such file or directory @ C:wampwwwgeeklog-1.7.1public_htmllib-common.php(1305) : eval()'d code line 53


You must give the full path to your file dl-logo.inc

::Ben

 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
I had no idea you could do that Big Grin


Yes... you can see the code in lib-common.php

Text Formatted Code

    // The following lines allow users to embed PHP in their templates.  This
    // is almost a contradition to the reasons for using templates but this may
    // prove useful at times ...
    // Don't use PHP in templates if you can live without it!

    $tmp = $header->finish($header->parse('index_header', 'header'));

    $xml_declaration = '';
    if ( get_cfg_var('short_open_tag') == '1' )
    {
        if ( preg_match( '/(<\?xml[^>]*>)(.*)/s', $tmp, $match ) )
        {
            $xml_declaration = $match[1] . LB;
            $tmp = $match[2];
        }
    }

    ob_start();
    eval( '?>' . $tmp );
    $retval = $xml_declaration . ob_get_contents();
    ob_end_clean();

    return $retval;


::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

All times are EST. The time is now 08:39 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content