Debugging a small syntax issue

I’ve been playing around with the code in this post.

It works well, except this line in the theme.php page:

	',(isempty($pageTitle) ? '' : $pageTitle.' - '),$siteTitle,'

Something in that line causes the code not to work, although I couldn’t get any errors to display. If I change it to something like this it works fine:

	', $pageTitle ,'

I’ve played around with it ad infinitum and just can’t see what the problem is, but I’m not proficient in PHP. Thanks for any help!

You haven’t said what result you actually did get. “Not work” is a little too obscure to make a judgement call on.

Can you at least tell us what output you are expecting to see and perhaps a var_dump(…) of the variables in question.

Yes, sorry for being vague. I was just hoping there was something obviously faulty in that line, like a typo.

If I run the code as given on that post (with the “your document” being an index.php file, for example, that calls the theme.php file), then index.php pulls in the doctype, meta links etc, but the <title> element is empty and the <body> element is also empty. So something stops working once the script hits the <title> part.

I’ve googled var_dump(), but from what I’ve read about it, I’m not sure where to place it within those files to do anything useful. Sorry for being such a noob at this.

I am no expert, but I think it should read:

    ',(empty($pageTitle) ? '' : $pageTitle.' - '),$siteTitle,'

I get an error about a call to an undefined function “isempty” when I use the original code, if I right-click and view source.

Hi Ralph,

For a PHP beginner it is one big chunk of code to try and understand :slight_smile:

biggest problem was the missing function isempty($val)

Try this:

ini_set('display_errors', true);

$pageTitle = 'Page Title';
$siteTitle = 'Site Title';
$pageShortName = 'Page Short Name';

echo  theme_header($pageTitle='',$siteTitle,$pageShortName);

echo 'Content blurb goes here';

echo theme_footer();

 following functions could/should be in separate include file:
 include  '/common-includes/directory/pageFunctions.php';

// file: pageFunctions.php
function isempty($val)
    $result = true;
        $result= false;
    return $result;

function theme_header($pageTitle='', $siteTitle, $pageShortName)
    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    content="text/html; charset=utf-8"
    (isempty($pageTitle) ? '' : $pageTitle.' - ')



<div id="pageWrapper">

    <ul id="mainMenu">
                $pageShortName=='home' ? ' class="current"' : ''
            ),' href="index.php">Home</a>
                $pageShortName=='portfolio' ? ' class="current"' : ''
            ),' href="portfolio.php">Portfolio</a>
                $pageShortName=='about' ? ' class="current"' : ''
            ),' href="about.php">About Us</a>
                $pageShortName=='blog' ? ' class="current"' : ''
            ),' href="blog.php">Our Blog</a>
                $pageShortName=='contact' ? ' class="current"' : ''
            ),' href="contact.php">Contact Us</a>
    <div id="content">';

function theme_footer()
    echo '
    <!-- #content --></div>
    <div id="footer">
        Site disclaimer here
    <!-- #footer --></div>
<!-- #pageWrapper --></div>



    Content blurb goes here    
            Site disclaimer here

Thanks droopsnoot. That does seem to be the issue with the line, as using just empty() makes it work. I didn’t think to check that. Nice work!

I actually find it pretty easy to understand. What I like about it is that you can have just one template for a whole site, rather than having lots of templates full of includes (the way I used to do static sites). I’ve been enjoying playing around with that code to see what I could do with it, but got stuck o that one line. It’s easy to find empty() in the PHP manual, but not isempty(), so I don’t know if it’s a mistake or has a different meaning, as I see lots of references to it on the web.