Forum for discussing general topics related to Couch.
14 posts Page 1 of 2
To clarify it a bit, i have a one page site and an array which contains all the necessary strings and urls for the page, basically the configuration.

What i now would like to have is a backend for the customer to comfortably edit the content of this array without having to open the php file in an editor.

The array looks sth like this:
Code: Select all
$demodata = array(
    "en" => array(
        "general" => array(
            "partner" => "Proud partner of"
        ),
        "content" => array(
            "about" => array(
                "navtitle"  => "about",
                "title"     => "about",
                "text"      => "ehu tnoehaotn suheoueosuhstunh sntetunh sntuhus stenhu sntoehuseno uhetnsuh sntuhsu nun stnuhus usnth unsooesnt ",
                "image"     => "assets/img/back2.jpg",
                "tabs"      => array(
                    "pubrel"    => array(
                        "title" => "Public Relation",
                        "text0"  => "1 ouh nuneu nuhnu nth  snontu hsnunuahtuao",
                        "text1"  => "1 ouh nuneu nuhnu nth  snontu hsnunuahtuao"
                    ),
                 ),
            ),
         )


Because couch is only parsing the output of a script i can't add the tags inside of the php array.
A workaround solution would be to store the php file as text, let couch parse it, then read it again, add the php tags and save it as a php file, but i was wondering if there was better way to achieve the same result.

Is it possible to load couch in php and then just 'ask' for the content with the id 'xxx' for example?

Cheers,
Lars
This question is similar to 'How to edit a php template from the back-end', so I'm interested, too..
I know some CMS that allow to do it by:
- converting php file to text
- let the user to edit
- converting text to php and execute

Some systems have an advanced option of 'drafts' or 'versions' of modified php file, so you can choose the previous version if made a mistake.
Have no idea how to make it without converting to text..

I also think that 'shortcodes' Couch feature is handy in some situations, but implementing it in your project could be too difficult..
Hi and welcome, Larzan.

@Musman, I think Larzan does not want the entire PHP code to be editable from the backend. It seems he wishes to replace only certain values of the PHP code with data entered into editable regions of Couch e.g. as follows -
"general" => array(
"partner" => "<cms:show my_partner />"
),

Have I understood correctly, Larzan?

If so, you have correctly identified the reason why we cannot use cms: tags within raw PHP - PHP code runs *before* Couch comes into the scene.

However, this can easily (usually) be resolved by making Couch execute the PHP code instead by doing this -
Code: Select all
<cms:php>
    ...
    "general" => array(
        "partner" => "[b]<cms:show my_partner />[/b]"
     ),
    ...
</cms:php>

That is - instead of <?php .. ?>, if you enclose the PHP code with <cms:php>..</cms:php> tags, now the code gets executed by Couch and so we can use Couch tags within it.

How you use this technique really depends on how your PHP code was being used by the original page. Please keep in mind that Couch is meant to retrofitted within *static* HTML pages and not those already using PHP.
Your mileage will vary depending on the use-case.

Hope this helps.
Thanks for your replies, i would have answered before but i didn't see that i was not automatically watching this topic.

So, KK, yes, thats exactly what i need to do.
It took me a while (never used couchcms before) but i got it to work then, neat feature this option.

To everybody as clueless as me, you obviously still have to have the standard couch inclusion tags, so the beginning and end of my file look like this:
Code: Select all
<?php require_once( 'couch/cms.php' );?>
<cms:php>
  $data = ....
</cms:php>
<?php COUCH::invoke(); ?>

with the couch replacement tags in between.

So this work very well, the only thing that you have to take into consideration is that it is a local inclusion/execution that couch does, therefore all the variables declared between the cms:php tag are only locally available.

As i was doing this in an include library i had to add

Code: Select all
$GLOBALS["demodata"] = $demodata;

at the end of the file to make the $demodata array available in the main file.
But with this it worked perfectly, thanks a lot.

Thanks a lot for your help, I will present this solution to the customer and we will see what they say :)
Hmm, i have a problem here and don't know if it is related to the cms:php tag or the fact that i include the php file into another, or if i am doing sth. wrong in general:

I have the discussed setup and everything works fine...
as long as i am logged in as superuser.

Even though i set the access level to 'Everyone' (backend and also tried it with the template tag) i can not access the data / render the frontpage correctly, when i am not logged in as superuser.

Am i missing sth. here?
Hi,

Who the logged-in user is shouldn't really make any difference.

Can you please check if you have enabled caching in the config file? That could be a possible reason.
Thanks for the quick answer, no, caching is deactivated...

Is it possible that it has to do with the cms:php tag?

Is there any logfile i could investigate?
As I said, cms:php shouldn't be affected by login status.

Could you please PM me all the related files?
Let me take a look at the code.

Thanks.
Received the files. Thanks.

I had a look and, I think, this is the problem -
you have nested <cms:php>..</cms:php> block within the <cms:template>..</cms:template> block. The cms:template block gets executed for only the super-admins and ergo the problem.

You can safely move the entire cms:php block out of the cms:template block and that should rectify the situation e.g.

Code: Select all
<cms:template title="Testtitle" access_level='0' >
    ... can remain empty..
</cms:template>

<cms:php>
   ...
   if (!isset($current_lang))
   ...
</cms:php>

Hope this helps.
Do let us know.
Yes, that makes sense.

I changed it to a single tag and it works flawlessly.

Thanks a lot :)
14 posts Page 1 of 2
cron