Forum for discussing general topics related to Couch.
13 posts Page 2 of 2
@Johnny2R, thanks for posting the code. I think I get it now.

We can get the same functionality in Couch by making the following changes -
1. The Couch version of the materpage would become as follows -
Code: Select all
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Meta Goes Here">

    <title><cms:show my_title /></title>
    <link rel="icon" href="favicon.ico" type="image/x-icon">
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <link href='https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700|Alegreya:400,300,700' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">

    <link rel="stylesheet" href="css/layouts/custom.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
   
    <cms:if my_header >
        <cms:show my_header />
    </cms:if>
</head>
<body>

<div class="container-fluid">
    <div class="row">
        <div class="col-xs-12 banner"><img src="img/banner.png"/></div>
    </div>
</div>


<div class="content">
    <div class="container-fluid">
        <div class="row">
            <cms:show my_content />
        </div>
    </div>
</div>

<div class="content">
    <div class="container-fluid">
        <div class="row footer">
            <div class="col-xs-12">© 2016 CouchCMS Testing</div>
        </div>
    </div>
</div>

<cms:if my_footer >
    <cms:show my_footer />
</cms:if>

</body>

</html>

We'll need to use this masterpage as an snippet so move the file to the 'couch/snippets' folder (or to whatever location you have configured this folder). I'm assuming that the file is named 'master.html'.

Now the Couch managed template that you were using PHP in to set the variables, would become as follows -
Code: Select all
<?php require_once('couch/cms.php' ); ?>

<!-- set 'my_title' variable -->
<cms:set my_title="Test Page" />
<cms:template title= "<cms:show my_title />" />

<!-- set 'my_header' variable -->
<cms:capture into='my_header'>
    <meta name="description" content="Test page meta description">
</cms:capture>

<!-- set 'my_content' variable -->
<cms:capture into='my_content'>
    <div>
        <h1>Real Content</h1>
        <cms:editable name='left_content' label="Left Content" type='richtext'>
            <p>Blah blah</p>
        </cms:editable>
    </div>
</cms:capture>

<!-- set 'my_footer' variable -->
<cms:capture into='my_footer'>
    <script type="text/javascript"></script>
</cms:capture>

<!-- eventually call the master page that will use the variables set above -->
<cms:embed 'master.html' />

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

As you can see, the calling page first sets variables named 'my_title', 'my_header', 'my_content' and 'my_footer' and then embeds the master page that makes use of those variables.

Does this help?
Thanks, that helps a lot. It is functionally identical to the native PHP version, but the exclusive use of the 'cms' tags makes it a lot cleaner, in my eyes. There is one minor downside to using the cms tags, though (which was equally applicable to the version I posted), and that is that the template then automatically becomes visible as a managed page in the Admin area, even when there are no editable regions on it. Is there a way of hiding pages in the Admin area if they have no editable regions? It would certainly be clearer for page editors if the only pages they could see were editable ones. [LATER: I see I can use "hidden = '1'" in the template tag for this purpose].

Incidentally, I was sure that what I needed to do could be done by CouchCMS, it was just not clear how it could be done. It might help from a documentation point of view if there were more examples of things like the cms:capture, etc., so that people like myself who area actually used to coding in various languages could more easily get a grasp of the CouchCMS way.

One thing which drew me to CouchCMS was its lightness and the ease with which I could retrofit CMS functionality into an existing site, but I was initially a little concerned about the emphasis on the fact that you didn't need to use any PHP at all to work with it - which is all very well as long as it doesn't actually imply a top-end limit on its capabilities.
I have something similar in my boilerplate which (IMO) looks cleaner:

Sample page:
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Home' />
<cms:embed 'header1.html' />

    <title><cms:get_custom_field 'site_name' masterpage='globals.php' /> - <cms:get_custom_field 'site_desc' masterpage='globals.php' /></title>
    <meta name="description" content="<cms:get_custom_field 'site_desc' masterpage='globals.php' />" />

<cms:embed 'header2.html' />

<div id="content">
    <h1><cms:get_custom_field 'site_name' masterpage='globals.php' /></h1>
    <h3><cms:get_custom_field 'site_desc' masterpage='globals.php' /></h3>
    <cms:editable name='main_content' type='richtext' label='Main Content'>
        <p>Hello world!</p>
    </cms:editable>
</div>

<cms:embed 'footer.html' /> 
<?php COUCH::invoke(); ?>


header1.html:
Code: Select all
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />


header2.html:
Code: Select all
<meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" href="<cms:show k_site_link />css/styles.css" />
    <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
    <script>window.jQuery || document.write('<script src="<cms:show k_site_link />js/vendor/jquery-1.12.0.min.js"><\/script>')</script>
    <script src="<cms:show k_site_link />js/menu.js"></script>
</head>


<body>
<div id="wrapper"> <!-- Closed in footer -->
   
<!--[if lt IE 9]>
    <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
   


<!-- Menu -->
<input type="checkbox" id="menubox" />
<nav class="clearfix">
    <label for="menubox">
        <img src="<cms:show k_site_link />img/icons/menu.png" id="menuicon" />
    </label>
    <ul>
        <li <cms:if k_template_name=='index.php'>class="current"</cms:if> ><a href="<cms:link 'index.php' />">Home</a></li>
        <li <cms:if k_template_name=='contact.php'>class="current"</cms:if> ><a href="<cms:link 'contact.php' />">Contact</a></li>
    </ul>
</nav>


footer.html:
Code: Select all
<div id="footer">
    <div id="couch">
        <p>&lt; &gt; with &hearts; and <a href="http://couchcms.com" title="CouchCMS - Simple Open-Source Content Management">Couch</a></p>
    </div>
</div>

       
</div> <!-- Wrapper div -->
</body>
</html>


Then to add scripts or whatever to specific pages, I just put a script tag between the two header snippets.

Also, just fyi, if ever you DO need to use straight php, you can do a <cms:php> tag :)
13 posts Page 2 of 2