Forum for discussing general topics related to Couch.
8 posts Page 1 of 1
If I am ging to use includes to control menus, headers, footers and the like, can I use Couch CMS to change these files so that they change universally across the site? If so, how would that work?
Normally there are two ways of using included files in Couch
1. You can keep on using the original PHP way of including files e.g.
<?php include("menu.php"); ?>

2. or (preferably) use Couch's cms:embed tag to do the same (you'll have to move the 'menu.php' to the 'snippets' folder) e.g.
<cms:embed "menu.php" />

Coming to your question -
..can I use Couch CMS to change these files so that they change universally across the site?

"use Couch CMS to change these files" - if by this you mean be able to modify the markup code contained within the included files from within the Couch admin panel, the answer is yes you can. Here is how -

Create a template, say named 'globals.php', and make it non-executable because we'll use it only to store the code for our included files (i.e. globals.php will never be accessed via its URL by th world at large)
Code: Select all
<cms:template executable='0' >

</cms:template>

and then create editable regions (of type textarea) for each of your include files. Make sure to set the no_xss_check to '1' to prevent Couch from sanitizing the HTML code entered within it. e.g.
Code: Select all
<cms:template executable='0' >
   <cms:editable name='menu_code' label="Menu code"
       height='100'
       no_xss_check='1'
       type="textarea"
   />
   <cms:editable name='footer_code' label="Footer code"
       height='100'
       no_xss_check='1'
       type="textarea"
   />
</cms:template>

Visit globals.php while logged-in as super-admin for Couch to pickup the changes.
In the admin panel you can now add the HTML code for each of the previously included files into their respectable editable regions.

To include the code entered within the editable regions created above into the rest of the templates of your site, use the cms:get_custom_field tag. e.g. change the
Code: Select all
<?php include("menu.php"); ?> 
or
<cms:embed "menu.php" />
in each of your templates to
Code: Select all
<cms:get_custom_field 'menu_code' masterpage='globals.php' />

Hope this answers your query.
Bringing up a very old topic here but I noticed you mentioned above to use <cms:embed "menu.php" />.

When I try and use this, the tag/code is displayed as text in the source and doesn't actually embed/include anything?
- Dan
Fixed...

I was stupid enough to miss the invoke script/function at the bottom of the template.
- Dan
I need to do the same thing where the user can change the menu item names and links, I currently have includes/header.php which looks like the following

Code: Select all
<!DOCTYPE html>
<html lang="en">

<head>
    <title><?php echo $title; ?></title>
    <meta charset="utf-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="<?php echo $pgDesc ?>">
   <link rel="stylesheet" href="./css/main.css" type="text/css" media="screen">
</head>
<body class="home cbp-so-scroller" id="cbp-so-scroller">

<!-- Mobile Menu  -->
<div class="header">
  <a href="#menu" class="button">menu</a>
  <a href="contact.php" class="btn">free quote</a>     
  <a class="tell" href="tel:"><span>Call</span> </a>
</div>

<!--MOBILE MENU-->
<div id="menu" >
  <ul class="menu_snap">
    <li><a href="index.php">Home</a></li>
    <li><a href="services.php">Services</a></li>
    <li><a href="sales.php">Sales</a></li>
    <li><a href="reviews.php">Reviews</a></li>
    <li><a href="contact.php">Contact</a></li>
  </ul>
</div>

<div class="site-container" id="home">
 
<!-- Header -->
<header class="site-header">
   <a href="index.php" class="logo"><img src="images/logo/nicom-logo-transparent.png" alt=""></a>
   <div class="top-header">
    <a href="contact.php" class="btn">free quote</a>     
    <p class="phone">
      <i class="fa fa-phone" aria-hidden="true"></i>
      <a href="tel:"></a>
    </p>
    <p class="companyname">
   
    </p>
    <ul class="socials">
      <li><a href="" target="_blank"><i class="fa fa-facebook" aria-hidden="true"></i></a></li>
      <li><a href="#" target="_blank"><i class="fa fa-twitter" aria-hidden="true"></i></a></li>
      <li><a href="#" target="_blank"><i class="fa fa-linkedin" aria-hidden="true"></i></a></li>
      <li><a href="#" target="_blank"><i class="fa fa-pinterest" aria-hidden="true"></i></a></li>
    </ul>

   </div>

<!-- DESKTOP MENU-->
  <!-- N A V  -->
  <nav id="nav" class="nav-primary" >

      <ul class="sf-menu menu menu_snap" id="sf-menu">
        <li><a href="index.php">Home</a></li>
       <li><a href="services.php">Services</a></li>
        <li><a href="sales.php">Sales</a></li>
        <li><a href="reviews.php">Reviews</a></li>
        <li><a href="contact.php">Contact</a></li>
      </ul>

  </nav>

</header>


I don't get how to do it following this guide, can anyone help please as need to get it done urgently
Hi, do you try a Nested Pages (AKA Menu Maker)?

DOCUMENTATION:
https://docs.couchcms.com/concepts/nested-pages-aka-menu-maker.html

Or simply make custom fields for Menu with links to pages.
I have not tried the nested pages yet, I have the pages design/layout and content already created so don't need to create them using nested pages

I have no idea how to make custom fields for the menu with links to the pages as never been asked to do it before this way
Could it be done with nested pages, for example the home page has a different design to the other 4 pages on the site so could could the home page have it's own design and the other 4 have the same design but different content so could I use nested pages and clone the 4 pages that have the same design and the home page have a different design

Hope someone can help as really stuck on this and need it done for the morning
8 posts Page 1 of 1