简体   繁体   中英

Joomla component rendering view <head> to <body>

I've created a component to use within Joomla and it seems to have an issue with working with my custom theme. The front page works perfectly but when going in to a component view, it seems to move the content that should be in head to the body tags. I've tried this with a default theme and it seems to work so i'm pretty confident that it is an issue with my personal theme.

<?php 

defined( '_JEXEC' ) or die( 'Restricted access' );

JHtml::_('jquery.framework');
$doc = JFactory::getDocument();

$doc->addStyleSheet('templates/' . $this->template . '/css/bootstrap.css');
$doc->addStyleSheet('templates/' . $this->template . '/css/style.css');
$doc->addScript('templates/' . $this->template . '/js/bootstrap.js', 'text/javascript');
$doc->addScriptDeclaration ("           jQuery('.carousel').carousel({
            pause: 'false'
        });");
?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>" >
<head>
    <jdoc:include type="head" />
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <div id="backspinner">
                <div id="back-carousel" class="carousel slide carousel-fade" data-ride="carousel">
                    <div class="carousel-controls">
                        <!-- Indicators -->
                        <ol class="carousel-indicators">
                            <li data-target="#back-carousel" data-slide-to="0" class="active"></li>
                            <li data-target="#back-carousel" data-slide-to="1"></li>
                        </ol>
                    </div>

                    <!-- Wrapper for slides -->
                    <div class="carousel-inner">
                        <div class="item active">
                            <img src="/templates/sheffieldford/images/back1.jpg" class="backimage">
                            <div class="carousel-caption">
                            ...
                            </div>
                        </div>
                        <div class="item">
                            <img src="/templates/sheffieldford/images/back2.jpg" class="backimage">
                            <div class="carousel-caption">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-2" id="headleft"></div>
            <div class="col-md-8" id="head">
                <div class="boundingbox">
                    <div class="row">
                        <div class="col-md-2 col-md-offset-1">
                            <img src="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template;?>/images/fordlogo.png" id="logo" class="fordlogo">
                        </div>
                        <div class="col-md-2 col-md-offset-2">
                            <a href="/"><img src="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template;?>/images/logo.png" alt="Logo" id="logo"/></a>
                        </div>
                        <div class="col-md-3 col-md-offset-2" id="callbox">
                            <div id="callboxtext">
                                <?php
                                    $article = JControllerLegacy::getInstance('Content')->getModel('Article')->getItem(2);
                                    echo $article->introtext;
                                ?>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="centered-pills">
                        <jdoc:include type="modules" name="navigation" />
                    </div>
                </div>
            </div>
            <div class="col-md-2" id="headright"></div>
        </div>
        <div class="row">
            <div class="col-md-8 col-md-offset-2">
                <div class="boundingbox">
                <jdoc:include type="component" />
                </div>
            </div>
        </div>
        <div class="row footerrow" id="footer">
            <div class="col-md-8 col-md-offset-2 col-xs-10 col-xs-offset-1">
                <div class="boundingbox">
                    <div class="row" style="margin:0px;">
                        <div class="col-md-6">
                            <div class="row">
                                <div class="col-md-4 footercolumn">
                                <h3>Accident Repairs</h3>
                                    <ul>
                                        <li>Ford Accident Management</li>
                                        <li>Accident Repairs</li>
                                        <li>Smart Repairs</li>
                                        <li>Dentals Paint Removal</li>
                                    </ul>
                                </div>
                                <div class="col-md-4 col-md-offset-2 footercolumn">
                                <h3>Vehicle Servicing</h3>
                                    <ul>
                                        <li>Ford Blue Service</li>
                                        <li>Service Plans</li>
                                        <li>Ford Warranty</li>
                                        <li>Special</li>
                                    </ul>
                                </div>
                            </div>
                            <div class="row footerrow hidden-xs hidden-sm">
                            <div class="col-md-4 footercolumn"  >
                                <img src="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template;?>/images/footerlogo.png" class="infoimage footerlogo"/>
                            </div>
                            <div class="col-md-4 footercolumn"  >
                                <img src="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template;?>/images/motalogo.png" class="infoimage footerlogo" style="margin-top: 11px;"/>
                            </div>
                            <div class="col-md-4 footercolumn" style="margin-top: 6px;">
                                <div class="footerimg">
                                    <a href="https://www.facebook.com/clarkandpartners" target="_blank"><img src="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template;?>/images/facebook.png" style="display: block;
                                            float: left;"/></a>
                                    <span class="spacer"></span>
                                    <a href="https://twitter.com/clark_partners" target="_blank"><img src="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template;?>/images/twitter.png" style="display: block;
                                            float: left;"/></a>
                                </div>
                            </div>
                        </div>
                        </div>
                        <div class="col-md-6">
                            <div class="col-md-4 col-md-offset-2" id="contactdetails">
                                <a href="#">Special Offers</a></br>
                                <a href="#">Ford Warranty</a></br>
                                <a href="#">About Us</a></br>
                                <a href="#">Customer Reviews</a></br>
                                <a href="#">Adaptations</a></br>
                                <a href="#">News</a></br>
                                <a href="#">Contact Us</a></br>
                            </div>
                            <div class="col-md-6" id="contactdetails">
                            <?php $article = JControllerLegacy::getInstance('Content')->getModel('Article')->getItem(3);
                                echo $article->introtext;?>
                            </div>
                        </div>
                        <div class="row footerrow hidden-md hidden-lg">
                            <div class="row">
                                <div class="col-xs-6 col-xs-offset-3 footerimgxs">
                                    <a href="https://www.facebook.com/clarkandpartners" target="_blank"><img src="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template;?>/images/facebook.png"/></a>
                                    <a href="https://twitter.com/clark_partners" target="_blank"><img src="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template;?>/images/twitter.png"/></a>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-xs-8 col-xs-offset-2 footercolumn"  >
                                    <div class="row footerimgxslogo">
                                        <img src="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template;?>/images/footerlogo.png"/>
                                    </div>
                                    <div class="row footerimgxslogo">
                                        <img src="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template;?>/images/motalogo.png"/>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

I've ready that other people have fixed the issue with changing the encoding to UTF8 with BOM but that hasn't seemed to change anything for me.

Assuming this is your custom template index.php file the issue is how you are incorporating the site component into your template. You are manually instantiating and rendering the component view when you should be using Joomla's statements.

Swap this code out:

<?php $article = JControllerLegacy::getInstance('Content')->getModel('Article')->getItem(3);
            echo $article->introtext;?>

For:

<jdoc:include type="component" />

You're component should render properly. In truth, there are numerous Joomla integration issues which are only going to further prevent proper management of your content from the administrators dashboard. Sections such as menus, logins, alerts and debugging all are assigned using modules.

If you haven't checked out the index.php for one of the core templates I would give it a review. Also attached a link to docs on creating Joomla templates.

Good luck!

https://docs.joomla.org/Portal:Template_Development

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM