Hi there, totally confused and hoping someone can help. I have an existing article template which suddenly developed this error when viewing the article: Parse error: syntax error, unexpected $end in /home/classicr/public_html/components/com_cobalt/views/record/tmpl/default_record_library.php on line 324

My confusion is because I was previously using the template without errors, and to the best of my knowledge nothing was changed. I certainly don't recall making changes at all - the site is under construction and I have been working on other things.

Anyway. I've tried everything I can think of, and run the code through a couple of online php checkers (I'm an utter novice). I did discover that there was an "unclosed" <?php tag, so closed it with ?> but it still returns an error. I've added the code in question here (the last line is the one indicated as incorrect) but will attach the whole file as well.

Basically, if I remove the ?> it then tells me the same thing and indicates the last } as being the problem. If I add the ?> it then indicates that this is the problem. I've done a count on the { and } and there are an equal number in the document, and I don't understand how I can have an opening <?php without the closing one?

Pretty please, can someone assist? I'm not doubt as dumb as I feel right now, but hours later I'm still at a loss and would really appreciate some help.

Many thanks,
Jude

Code is below:

<?php
function group_start($data, $label, $name)
{
    static $start = false;
    switch ($data->tmpl_params['record']->get('tmpl_params.item_grouping_type', 0))
    {
        //tab
        case 1:
            if(!$start)
            {
                echo '<div class="tab-content" id="tabs-box">';
                $start = TRUE;
            }
            echo '<div class="tab-pane" id="'.$name.'">';
            break;
        //slider
        case 2:
            if(!$start)
            {
                echo '<div class="accordion" id="accordion2">';
                $start = TRUE;
            }
            echo '<div class="accordion-group">
                <div class="accordion-heading">
                    <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#'.$name.'">
                         '.$label.'
                    </a>
                </div>
                <div id="'.$name.'" class="accordion-body collapse">
                    <div class="accordion-inner">';
            break;
        // fieldset
        case 3:
            echo "<legend>{$label}</legend>";
        break;
    }
}

function group_end($data)
{
    switch ($data->tmpl_params['record']->get('tmpl_params.item_grouping_type', 0))
    {
        case 1:
            echo '</div>';
        break;
        case 2:
            echo '</div></div></div>';
        break;
    }
}

function total_end($data)
{
    switch ($data->tmpl_params['record']->get('tmpl_params.item_grouping_type', 0))
    {
        //tab
        case 1:
            echo '</div>';
        break;
        case 2:
            echo '</div>';
        break;
    }
}

?>

Okay, it won't let me add the whole txt file? Not sure what I should do now...

Recommended Answers

All 10 Replies

Parse error: syntax error, unexpected $end

Most of the time this is a missing curly bracket somewhere.

default_record_library.php

upload above file as zip

I dont see any error in code posted by you

Thank you, I've uploaded the zip file as requested

In lines 229 and 235 you have forgotten the <?php endif; ?> (added below)

<div id="excerpt">
        <div>
            <p><span id="label"><b>Excerpt:</b></span>
            <div style="float:left;">
                <div><?php if(!empty($item->fields_by_id[32])):?><?php echo $item->fields_by_id[32]->result; ?><?php endif; ?></div>
            </div>
        </div>
    </div>

    <div id="memreview">
        <div><?php if(!empty($item->fields_by_id[14])):?><?php echo $item->fields_by_id[14]->result; ?><?php endif; ?></div>
    </div>

I have also noticed that you have some extra opening and closing tags in lines 145 to 150:

<div class="page-header">
                <<?php echo $params->get('tmpl_params.title_tag', 'h1')?>>
                    <?php echo $item->title?>
                    <?php echo CEventsHelper::showNum('record', $item->id);?>
                </<?php echo $params->get('tmpl_params.title_tag', 'h1')?>>
            </div>

Completely unrelated, but I recently kept getting that error when a file had not completed uploading.

I agree with simplypixie,

added following code for field_by_id[32] and field_by_id[14]

<?php endif; ?>

Note: I just want to clarify that the reason for my post is because I had been getting that error a lot, and I clicked into this thread based on its title, and so I just wanted to provide an alternative solutions to others who might stumble upon this thread.

Hi there. I have added the recommended endif's as per responses above, but unfortunately it hasn't solved my problem. When opening the article I still get the following error:

Parse error: syntax error, unexpected $end in /home/classicr/public_html/components/com_cobalt/views/record/tmpl/default_record_library.php on line 598

This is the last } in the file. I have attached the latest zip file.

Thank you for taking the time to look at this for me. My apologies for not responding sooner - it's a rather intense time of year.

Talking of which - a very successfull, happy and productive New Year to the team!

I don't mean to sound rude but you really need to find a way to look through your code and find errors for yourself as that is all I am doing for you by closing/minimizing blocks of code or saving to a new file and then putting sections back until you find the one that has the missing closing tag (which causes the error you are getting).

Again, you have a mising endif statement in your code on line 460:

<div><?php if(!empty($item->fields_by_id[14])):?><?php echo $item->fields_by_id[14]->result; ?></div>

Should be:

<div><?php if(!empty($item->fields_by_id[14])):?><?php echo $item->fields_by_id[14]->result; ?><?php endif; ?></div>

When doing these inline if statements, you can use the following shorthand instead:

<?= $value ? 'true' : 'false' ?>

So in other words ...

<?= !empty($item->fields_by_id[14]) ? $item->fields_by_id[14]->result : '' ?>

Much cleaner for use in templates. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.