Problems, need help? Have a tip or advice? Post it here.
9 posts Page 1 of 1
Hi Guys and Girls,

So I am in the middle of building my own site using Couch as a under the hood to which I followed the tutorial and obviously changed where applicable.

Now I'm also doing tidying at the same time so rather than having masses amount of code I tend to separate where required, header.php content.php footer.php (Similar to wordpress)

So my index.php looks a bit like this

Code: Select all
<?php include( 'header.php' ) ?>
<cms:template title='Homepage' />
<cms:pages>   
    <!-- Main Body -->
   
    <div class="container">
        <div class="row">
           
            <!-- Main Content -->
            <div class="col-md-8 main">
            <?php include ( 'content.php' ) ?>
           
            </div>
           
                        <!-- Sidebar -->
            <div class="col-md-4 main">
            <cms:embed 'sidebar.html' />
            </div>
        </div>
    </div>
</cms:pages>       
<?php include( 'footer.php' ) ?>


The sidebar doesn't appear to be working on this case. Just drops the divbox there and doesn't do anything to populate it.

This is my main page to which the sidebar suddenly works only its appeared twice. (there are two entries on the review page if your wondering)

Code: Select all
<?php require_once( 'admin/cms.php' ); ?>

<cms:template title='Reviews' clonable='1' commentable='1'>

    <cms:editable name='review_content' type='richtext' />
   
    <cms:editable name='review_img' crop='1' width='610' height='150' type='image' />
   
    <cms:folder name="reviews" title="Reviews" />
    <cms:folder name="latest" title="Latest News" />
   
</cms:template>

<cms:if k_is_page >
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title>GameLadder Network - <cms:show k_page_title /></title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="stylesheet.css" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
   
<body>
   
    <!-- Nav Bar -->
   
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <a href="index.php"><img src="img/logo.png" /></a>
            </div>
            <ul class="nav navbar-nav">
            <li class="active"><a href="index.php">Home</a></li>
            <li><a href="news.php">News</a></li>
            <li><a href="about.php">About</a></li>
            <li><a href="team.php">Meet The Team</a></li>
            <li><a href="reviews.php">Reviews</a></li>
            <li><a href="media.php">Media</a></li>
            <li><a href="twitch.php">Twitch Streamers</a></li>
            <li><a href="contact.php">Contact Us</a></li>
            </ul>
           
            <ul class="nav navbar-nav navbar-right">
                <li><a href="admin/login.php"><span class="glyphicon glyphicon-log-in"></span>   Login</a></li>
            </ul>
        </div>
    </nav>
   
    <!-- Carousel -->
   
    <div id="myCarousel" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
        <ol class="carousel-indicators">
            <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
            <li data-target="#myCarousel" data-slide-to="1" ></li>
            <li data-target="#myCarousel" data-slide-to="2" ></li>
        </ol>
       
        <!-- Wrapper for the slides -->
        <div class="carousel-inner">
            <div class="item active bannerimg">
                <img src="img/banner/img1.png" alt="Frostpunk" />
                <div class="carousel-caption carousel-caption-new">
                <h3>FrostPunk (PC)</h3>
                    <p>Can you survive the end of the world?</p>
                </div>
            </div>
        </div>
       
          <!-- Left and right controls -->
  <a class="left carousel-control" href="#myCarousel" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#myCarousel" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
    <span class="sr-only">Next</span>
  </a>
       
    </div>
       
    <div class="container">
        <div class="row">

            <div class="col-md-8 main">   
   
    <!-- Title -->
               
    <h3 class="title"><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></h3>
               
    <p class="sub"><cms:show k_page_foldertitle /> &bull; <cms:date k_page_date format='jS M, y'/><cms:date k_page_date format='jS M, y'/> &bull; <cms:show k_comments_count /> Comments</p>
               
    <!-- Image -->
    <img src="<cms:show review_img />" alt="" /> 
               
    <!-- Content -->
    <cms:show review_content />
   
    <!-- Comments -->
    <cms:embed 'comments_form.html' />
               
             <!-- Comment's List -->
         <h3>Comments</h3>
         <div class="hr dotted clearfix">&nbsp;</div>
         
         <cms:if k_comments_count >
         <ol class="commentlist">
            <cms:comments page_id=k_page_id order='asc' limit='5' paginate='1' >
            <li class="comment">
               <div class="gravatar">
                  <cms:gravatar email="<cms:show k_comment_author_email />" size="60" />
                  <a name="<cms:show k_comment_anchor />">
               </div>
               <div class="comment_content">
                  <div class="clearfix">
                     <cite class="author_name"><a href=""><cms:show k_comment_author /></a></cite>       
                     <div class="comment-meta commentmetadata"><cms:date k_comment_date format='F j, Y'/> at <cms:date k_comment_date format='h:ia'/></a></div>
                  </div>
                  <div class="comment_text">
                     <p><cms:show k_comment /></p>
                  </div>
               </div>
            </li>
            <cms:paginator />
            </cms:comments>
         </ol>
         <cms:else />
            No comments.
         </cms:if>
   
        </div>

        </div>
        <div class="main">
        <cms:embed 'sidebar.html' />
        </div>
    </div>
</body>
</html>
<cms:else />
    <cms:embed 'review_list.php' />
</cms:if>

<?php COUCH::invoke(); ?>
Hi,

A few points -

1. Please post the code contained in sidebar.html.

2. On the template where it appears twice (and there are also two review cloned pages), the relevant code would be in review_list.php (and not the one you posted) and I think you have managed to embed sidebar there within the <cms:pages> loop - so as many sidebars as there are cloned pages. Please check.

3. Finally, instead of using PHP includes, you can use <cms:embed> to ''chunk' up templates (like WordPress, as you said).
This is my side bar

Code: Select all
<cms:if k_is_page >
    <h4>Latest Reviews</h4>
    <ul class="Sidebar">
    <cms:pages masterpage='reviews.php' limit='4'>
    <li><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></li>
    </cms:pages>
    </ul>
</cms:if>


and review_list page

Code: Select all
<?php require_once( 'admin/cms.php' ); ?>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title>GameLadder Network - <cms:show k_page_title /></title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="stylesheet.css" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
   
<body>
   
    <!-- Nav Bar -->
   
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <a href="index.php"><img src="img/logo.png" /></a>
            </div>
            <ul class="nav navbar-nav">
            <li class="active"><a href="index.php">Home</a></li>
            <li><a href="news.php">News</a></li>
            <li><a href="about.php">About</a></li>
            <li><a href="team.php">Meet The Team</a></li>
            <li><a href="reviews.php">Reviews</a></li>
            <li><a href="media.php">Media</a></li>
            <li><a href="twitch.php">Twitch Streamers</a></li>
            <li><a href="contact.php">Contact Us</a></li>
            </ul>
           
            <ul class="nav navbar-nav navbar-right">
                <li><a href="admin/login.php"><span class="glyphicon glyphicon-log-in"></span>   Login</a></li>
            </ul>
        </div>
    </nav>
   
    <!-- Carousel -->
   
    <div id="myCarousel" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
        <ol class="carousel-indicators">
            <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
            <li data-target="#myCarousel" data-slide-to="1" ></li>
            <li data-target="#myCarousel" data-slide-to="2" ></li>
        </ol>
       
        <!-- Wrapper for the slides -->
        <div class="carousel-inner">
            <div class="item active bannerimg">
                <img src="img/banner/img1.png" alt="Frostpunk" />
                <div class="carousel-caption carousel-caption-new">
                <h3>FrostPunk (PC)</h3>
                    <p>Can you survive the end of the world?</p>
                </div>
            </div>
        </div>
       
          <!-- Left and right controls -->
  <a class="left carousel-control" href="#myCarousel" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#myCarousel" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
    <span class="sr-only">Next</span>
  </a>
       
    </div>
    <div class="container">
   
    <div class="row">
<cms:pages masterpage='reviews.php' paginate='1' limit='4' >


    <div class="col-md-8 main">
     
         <!-- Title -->
    <h3 class="title"><a href="<cms:show k_page_title />"><cms:show k_page_title /></a></h3>
                <p class="sub"><cms:show k_page_foldertitle /> &bull; <cms:show k_page_date formate='jS M, y' /> &bull; <cms:show k_comments_count /> Comments</p>
               
    <!-- Review Image -->
    <img class="thumb" src="<cms:show review_img />" />
   
    <!-- Content -->
    <cms:excerptHTML count='30' ignore='img'><cms:show review_content /></cms:excerptHTML>

    <!-- Read More Button -->
       
    <a href="<cms:show k_page_link />" class="btn btn-default">Read More</a>
   
    </div>


<cms:if k_paginated_bottom >
    <!-- Navigation Buttons -->
   
    <cms:if k_paginate_link_next >
        <a href="<cms:show k_paginate_link_next />" class="btn btn-default">&lt;&lt; Previous Posts</a>
    </cms:if>
   
    <cms:if k_paginate_link_prev >
        <a href="<cms:show k_paginate_link_prev />" class="btn btn-default">Next Posts >></a>
    </cms:if>
   
</cms:if>
   
<div class="main">
        <cms:embed 'sidebar.html' />
        </div>

</cms:pages>
                 
        </div>
    </div>
</body>
</html>
<?php COUCH::invoke(); ?>


I tried using the embed but i'm left with a blank page?
Thanks.

1.
The reason why the sidebar is not working on the index page is this -
You are using the following (abbreviated) code in index.php where the sidebar is being called from within a <cms:pages> block
Code: Select all
<cms:pages>    
   
    <!-- Sidebar -->
    <cms:embed 'sidebar.html' />

</cms:pages>

Now index.php is a non-clonable template - the code will execute but it will *never* set 'k_is_page' variable to '1' (that happens only with page-views of clonable templates).
Your sidebar code happens to be checking for this 'k_is_page' variable and hence it fails on index.php.

The solution is to remove the <cms:pages> and its closing </cms:pages> tag from index.php - it is redundant in a non-clonable template and the currently enclosed code in it will run without it.

2. As for the sidebar being repeated in list-view of reviews, as I suspected, you have plcaed it within the <cms:pages> block -
Code: Select all
    ..
    <div class="main">
    <cms:embed 'sidebar.html' />
    </div>

</cms:pages>

Anything placed within <cms:pages> block will repeat for as many times as there are cloned pages fetched by the tag and that is what is happening with the sidebar.

As the solution, please move the <cms:embed 'sidebar.html' /> statement to place it somewhere outside the closing </cms:pages> tag.

Hope this helps.
I will give this a try tonight once i've reinstalled my pc.

What about the embed bit? My header and footer have the embed parts and are in the snippets but for some reason it just comes up as a blank page?
If the embedded snippets have raw PHP code in them, that will require some tweaking.
Please see the following - viewtopic.php?f=2&t=11139
Only raw PHP code is has it the required by CouchCMS

Code: Select all
<?php require_once ( ' ../cms.php' ) ?>
Only raw PHP code is has it the required by CouchCMS
<?php require_once ( ' ../cms.php' ) ?>

Please allow me to clarify a misunderstanding here -
Couch requires those lines only in templates (and not snippets).

To explain the terms -
a template is a .php file that is accessible from the frontend through the browser (i.e. has a URL of its own) e.g. blog.php, contact.php
a snippet, on the other hand, is never accessed directly through browser (it is tucked away into its 'snippets' folder) and is only meant to be included within templates mentioned above.

So, e.g., in your case 'reviews.php' is a template (you access it through browser) while the embedded 'review_list.php' is a snippet (only adds content to reviews.php and is never itself accessed directly through the browser).

If the difference is still fuzzy, please take a look a the following post - viewtopic.php?f=2&t=7731#p18095

So, you can safely remove those PHP lines from all your snippets (e.g. header.php, content.php etc.).
Ahhh I got it all now! This all works! I found a way of making it outside the page commands.

Works on all pages now :D
9 posts Page 1 of 1
cron