Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
problem in embedding php file what is the proper way to embed file. has you can see in picture there is some problem i cant figure it out. i used <cms:embed 'menu.php' /> in my page and menu.php source code is
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>

<cms:template title='Menus' />
<div class="header-top">
      <div class="container">
         <div class="header-top-in">
            <cms:editable name='main_content' type='richtext'>
            <ul class="support">
               <li ><a href="mailto:info@example.com" ><i > </i>info@7heaven.co.in</a></li>
               <li ><span ><i class="tele-in"> </i>9880940198</span></li>         
                    <li ><span ><i ><img src="images/Whatsapp-icon.png" class="img-responsive"> </i>7760090007</span></li>         
            </ul>
                 </cms:editable>
                <ul class=" support-right">
                 </ul>
            <ul class=" support-right">
                <div class="search" >
           
                  <form action="search.php">
                     <input type="text" value="Keywords" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Keywords';}" class="text">
                     <input type="submit" value="SEARCH">
                  </form>
                     <div class="close-in"><img src="images/close.png" alt="" /></div>
         </div>
                <div class="search-in">
         
         
                  <div class="right"><button> </button></div>
            </div>
               <i class=" menber "> </i>
                   <?php
include 'js/connect_to_mysql.php';
if(isset($_SESSION['userid']) && $_SESSION['userid'] != ''){ // Redirect to secured user page if user logged in
   
   echo
               '<li  >Welcome:&nbsp;<a href="/"  style=" color:#FFF;font-weight:bolder;font-size:14px; ">'.$_SESSION['username'].'</a></li>
               <li ><a href="logout.php" ><i class="tele"> </i>Logout   </a></li>';   
   
}
else
{
   echo
               '<li ><a href="login.php" ><i class="men"> </i>Login</a></li>
               <li ><a href="signup.php" ><i class="tele"> </i>Create an Account</a></li>';
}


?>
            
            </ul>
            <div class="clearfix"> </div>
         </div>
         </div>
         <div class="header-bottom">
         <div class="container">         
            <div class="logo" style="z-index:999; margin-top:-15px;  ">
               <h1><a href="/"><img src="images/7.png" class="img-responsive"> </a></h1>
            </div>
            <div class="top-nav">
            <!-- start header menu -->
      <ul class="megamenu skyblue">
         
         
         <li class="active grid"><a  href="#">Destination</a>
            <div class="megapanel">
               <div class="row">
                  <div class="col1">
                        <div class="h_nav">
                        
                        <ul>
                           <li><a href="Coorg.php">Coorg</a></li>
                           <li><a href="Chikmagalur.php">Chikmagalur</a></li>
                           <li><a href="Ooty.php">Ooty</a></li>
                           <li><a href="Wayanad.php">Wayanad</a></li>
                           
                        </ul>   
                     </div>                  
                  </div>
                  <div class="col1">
                        <div class="h_nav">
                        
                        <ul>
                           
                           <li><a href="Mysore.php">Mysore</a></li>
                           <li><a href="Bangalore.php">Bangalore</a></li>
                                    <li><a href="Mangalore.php">Mangalore</a></li>
                        </ul>   
                     </div>                  
                  </div>
                  <div class="col1 col5">
                     <iframe src="https://www.youtube.com/embed/OlhLOWTnVoQ"  webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
                  </div>
                  
               </div>
               
           </div>
         </li>   
           
            <li><a  href="#">Services</a>
            <div class="megapanel">
               <div class="row">
                  <div class=" col-nav ">
                     <div class="h_nav">
                        
                        <div class="sell">
                           <div class="men">
                                   
                              <a href="#">
                                        <img src="images/Adventure.jpg" alt="" ></a>
                           </div>
                           <div class="men-in">
                        <h3>Adventure<br> Activities</h3>      
                              
                           </div>
                           <div class="clearfix"> </div>
                        </div>   
                        <div class="sell">
                           <div class="men">
                              <a href="#"><img src="images/Tours.jpg" alt=""  ></a>
                           </div>
                           <div class="men-in">
                              <h3> Tours& <br>Travels</h3>
                              
                           </div>
                           <div class="clearfix"> </div>
                        </div>   
                        <div class="sell">
                           <div class="men">
                              <a href="#"><img src="images/BikeRental.jpg" alt="" ></a>
                           </div>
                           <div class="men-in">
                           <h3> BikeRental</h3>
                           </div>
                           <div class="clearfix"> </div>
                        </div>   
                                <div class="sell">
                           <div class="men">
                              <a href="#"><img src="images/socialservice.jpg" alt="" ></a>
                           </div>
                           <div class="men-in">
                              <h3> Social<br>Services</h3>
                           </div>
                           <div class="clearfix"> </div>
                        </div>
                               
                               
                     </div>                     
                  </div>
                  <div class=" col-nav ">
                     <div class="h_nav">
                        
                        <div class="sell">
                           <div class="men">
                           <a href="#"><img src="images/events-activities.png" alt="" ></a>
                           </div>
                           <div class="men-in"><h3> Events& <br>Activities </h3>
                           </div>
                           <div class="clearfix"> </div>
                        </div>   
                        <div class="sell">
                           <div class="men">
                              <a href="#"><img src="images/holiday.jpg" alt="" ></a>
                           </div>
                           <div class="men-in">
                              <h3> Holiday<br>Packages</h3>
                           </div>
                           <div class="clearfix"> </div>
                        </div>   
                        <div class="sell">
                           <div class="men">
                              <a href="#"><img src="images/RealEstate.jpg" alt="" ></a>
                           </div>
                           <div class="men-in">
                              <h3> Real Estate</h3>
                           </div>
                           <div class="clearfix"> </div>
                        </div>   
                               
                                <div class="sell">
                           <div class="men">
                              <a href="#"><img src="images/coorgproduct.jpg" alt="" ></a>
                           </div>
                           <div class="men-in">
                              <h3> Coorg<br>Products</h3>
                           </div>
                           <div class="clearfix"> </div>
                        </div>
                               
                     </div>                     
                  </div>
                       
                       
               </div>
                 </div>
            </li>
            
            
            <li><a  href="http://www.evergreencounty.com/">Evergreen County</a>
               
              <div class="megapanel " >
               <div class="row">
               <center>   <img src="images/EvergreenCountyThumbnail.jpg" class="img-responsive img-rounded "   ></center>
                  
               </div>
                 </div> 
               
               
            </li>
                <li><a  href="7Heaven_Adventure.php">7heaven Adventure Zone </a>
            <div class="megapanel " >
               <div class="row">
               <center>   <img src="images/7HeavenAdventureActivities.jpg" class="img-responsive img-rounded "   ></center>
                  
               </div>
                 </div>   
            </li>
       </ul>
       <!---->
      
              <script type="text/javascript">
                     $('.search').hide();
                     $('button').click(function (){
                     $('.search').show();
                     $('.text').focus();
                     }
                     );
                     $('.close-in').click(function(){
                     $('.search').hide();
                     });
                  </script>

               <!---->

              <div class="clearfix"> </div>
               <!---->
            </div>
            
         </div>
         <div class="clearfix"> </div>
      </div>
      </div>
        <?php COUCH::invoke(); ?>

Attachments

Hi @gopi,

I gather from your post that you are using 'menu.php' as a snippet (i.e. menu.php is placed in the 'snippets' folder and then embedded in other templates using cms:embed).

In which case, you don't need to use <?php require_once( 'couch/cms.php' ); ?> and <?php COUCH::invoke(); ?> in menu.php - these lines are required only in the main templates i.e. those that will be accessible directly through browsers by their URLs e.g. http://www.yoursite.com/blog.php. In your case you won't be accessing menu.php as http://www.yoursite.com/menu.php and so it won't need the two PHP lines.

Second point that you need to know about snippets is that, unlike the main templates, you *cannot* run PHP code directly from snippets. Which is why you are seeing the PHP code in the snippet being outputted verbatim.

To run PHP code, you'll have to change <?php and ?> into <cms:php> and </cms:php>. So the PHP part of your snippet will become as follows -
Code: Select all
<cms:php>
include 'js/connect_to_mysql.php';
if(isset($_SESSION['userid']) && $_SESSION['userid'] != ''){ // Redirect to secured user page if user logged in
   
   echo
               '<li  >Welcome:&nbsp;<a href="/"  style=" color:#FFF;font-weight:bolder;font-size:14px; ">'.$_SESSION['username'].'</a></li>
               <li ><a href="logout.php" ><i class="tele"> </i>Logout   </a></li>';   
   
}
else
{
   echo
               '<li ><a href="login.php" ><i class="men"> </i>Login</a></li>
               <li ><a href="signup.php" ><i class="tele"> </i>Create an Account</a></li>';
}


</cms:php>

That said, I see that you are also defining editable regions within the snippet.
This can lead to an unexpected side-effect - assuming that you'll embed 'menu.php' in several main templates, those editable regions will get defined in *all* those templates (as menu.php now simply becomes a part of those templates).

I think that is not what you want.
If the idea is to define some editable regions that are common to all (or many) templates, please use a 'global' template for those (as explained in our tutorial - http://docs.couchcms.com/tutorials/port ... bal-values).

Hope it helps.
2 posts Page 1 of 1