Problems, need help? Have a tip or advice? Post it here.
5 posts Page 1 of 1
Ok guys...as I said my life spins on your cms (we bought so many licences that i don't even remember lol) that's why your support is always the best, the quickest and the kindest.

Now i have a problem:

I have a website that takes content from a page called data.php with the following structure:

Code: Select all


<?php

$hash_frag = $_GET['_escaped_fragment_'];

$content = array(

"page-1" => 'content page 1',
   
"page-2" => 'content page 2',
   
...

"page-n" => 'content page n'



);

if(isset($hash_frag)) {
    echo $content[$hash_frag];
}

?>



the code in the index.html is pretty easy

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>



<script type="text/javascript">
var escapedHash;

function findHash() {
    if(window.location.hash) {
        //$("#content").html("Loading...");
       
        escapedHash = window.location.hash.replace("#!", "");
        //alert(escapedHash);
       
        $.get("data.php?_escaped_fragment_=" + escapedHash, function(data) {
            $("#content").html(data);
        });
    }
}

$(document).ready(function() {
    findHash();
});

$(window).bind('hashchange', function() {
    findHash();
});
</script>

</head>

<body>


<ul id="nav">
<li><a href="#!page-1">Page-1</a></li>
<li><a href="#!page-2">Page-2</a></li>
...
<li><a href="#!page-n">Page-n</a></li>
</ul>


<div id="content"></div>

</body>
</html>



Now...I would like to take the file data.php and make the content areas editable by couch so the clients can edit their own pages...

Even under one template "data.php" and every page is an editable region if this is the way...

please tell me that is possible.

Thanks heaps like usually

Best
Hi Emanuale,

First of all thank you very much for supporting Couch :)

Now to the problem you have -
The way 'data.php' works in your setup is that it accepts a parameter named '_escaped_fragment_' via its querystring
$hash_frag = $_GET['_escaped_fragment_'];

and then it outputs data that is associated with '_escaped_fragment_'.
Actually '_escaped_fragment_' represents a discrete page ('page-1', 'page-n' etc.) but in your setup the data for all the pages is contained in the same physical file using an array.

The way I'll approach this problem using Couch is by making 'data.php' a clonable template with one editable region to hold the content
Code: Select all
<?php require_once 'couch/cms.php'; ?>

   <cms:template clonable='1'>
      <cms:editable name="my_content" type="richtext" />
   </cms:template>

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

and then creating a cloned page each for the 'page-1', 'page-n' etc.

Next, we'll check for the '_escaped_fragment_' parameter that comes through the querystring. The modified code becomes
Code: Select all
<?php require_once 'couch/cms.php'; ?>

   <cms:template clonable='1'>
      <cms:editable name="my_content" type="richtext" />
   </cms:template>

   <cms:set my_page="<cms:gpc '_escaped_fragment_' method='get' />" />

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

Notice that we are using cms:gpc (stands for Get/Post/Cookie) tag to do so.
The 'my_page' variable will hold the parameter being passed.

Finally, we'll simply fetch the cloned page with the name now being held in 'my_page' and output its content using cms:pages tag. The final code is
Code: Select all
<?php require_once 'couch/cms.php'; ?>

   <cms:template clonable='1'>
      <cms:editable name="my_content" type="richtext" />
   </cms:template>

   <cms:set my_page="<cms:gpc '_escaped_fragment_' method='get' />" />
   
   <cms:pages page_name=my_page >
      <cms:show my_content />
   </cms:pages>

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

This completes the 'data.php'.
If you wish, you can also convert the 'index.html' into a Couch template. Doing this will allow you create the <ul><li> menu automatically.

The original code in index -
Code: Select all
<ul id="nav">
   <li><a href="#!page-1">Page-1</a></li>
   <li><a href="#!page-2">Page-2</a></li>
   <li><a href="#!page-n">Page-n</a></li>
</ul>

can be made -
Code: Select all
<ul id="nav">
<cms:pages masterpage='data.php' >
   <li><a href="#!<cms:show k_page_name />"><cms:show k_page_title /></a></li>
</cms:pages>
</ul>

Everytime a cloned page gets added to 'data.php', the menu in index will change accordingly.

Hope this helps. Do let me know.
Thanks.
it does...is awesome...it's just perfect.....awesome

just one thing...in this way, all the pages need to be clonated. but what about if in one page in need a contact form or a flash player? i mean unfortunately the datas are not plane text for every page.... :( how can i do?

thanks I really appreciate every answer you give me KK really...

thanks again
Hey Emanuale,

I am terribly sorry but I missed the query in your response completely
but what about if in one page in need a contact form or a flash player? i mean unfortunately the datas are not plane text for every page

If you have not already found a solution, could you please let me know exactly what kind of page or data is giving you trouble?
I'll require the exact data to see what is going wrong.

Sorry again for the delay in response.
HI, there is nothing to be sorry about, at the end of the day, I'm sure you are busy somehow, anywa in general I need to see understand If a page has a different template from the cloned one i.e not just richtext. what about let's say, the home page has the rich text content, that there is a portfolio page but i still need to load the data from that template :)

is that clear?

thanks again really :)
5 posts Page 1 of 1