Forum for discussing general topics related to Couch.
6 posts Page 1 of 1
Dear community,

I am building a multi-lingual website and coded the prettyURL functionality myself by redirecting every URL request to "index.php" (as specified in the .htaccess file):

.htaccess
Code: Select all
RewriteEngine On

# if the requested url query is not a file
RewriteCond %{REQUEST_FILENAME} !-f
# and if the requested url query is not a directory
RewriteCond %{REQUEST_FILENAME} !-d

# always redirect to "index.php"
RewriteRule ^(.*)$ index.php


In the "index.php", I then declare all the CouchCMS editables and require a specific .php file based on some previous code.

index.php
Code: Select all
<?php require_once( "../couch/cms.php" ); ?>

<?php
// some queries performed here
?>

<cms:set my_lang = "<cms:php>echo $GLOBALS['selected_lang'];</cms:php>" />

<cms:template title="Home">     
    <cms:editable name="home_h1" type="text" />
    <cms:editable name="home_paragraph_<cms:php>echo $GLOBALS['available_languages'][0];</cms:php>" type="text" />
    <cms:editable name="home_paragraph_<cms:php>echo $GLOBALS['available_languages'][1];</cms:php>" type="text" />
</cms:template>

<cms:template title="About">
    <cms:editable name="about_h1_<cms:php>echo $GLOBALS['available_languages'][0];</cms:php>" type="text" />
    <cms:editable name="about_h1_<cms:php>echo $GLOBALS['available_languages'][1];</cms:php>" type="text" />
    <cms:editable name="about_paragraph_<cms:php>echo $GLOBALS['available_languages'][0];</cms:php>" type="text" />
    <cms:editable name="about_paragraph_<cms:php>echo $GLOBALS['available_languages'][1];</cms:php>" type="text" />
</cms:template>

<cms:template title="404"> 
    <cms:editable name="error_<cms:php>echo $GLOBALS['available_languages'][0];</cms:php>" type="text" />
    <cms:editable name="error_<cms:php>echo $GLOBALS['available_languages'][1];</cms:php>" type="text" />
</cms:template>

<?php

// REDIRECT TO ACTUAL PAGE
   
   // 1.) if no query in URL, go to home page
   if ( empty($qs_part1) ) {
       require_once($qs_part2 . ".php");
   }
   // 2.) if only language is in query string but nothing else, go to home page as well
   else if ( !empty($qs_part1) && empty($qs_part2)
        && in_array($qs_part1, $available_languages)
           ) {
       require_once($qs_part2 . ".php");
   }
   // 3.) if language and filename are in query string, go to home page as well
   else if ( !empty($qs_part1) && !empty($qs_part2)
             && in_array($qs_part1, $available_languages)
             && in_array($qs_part2, $pagesFilenames)
           ) {
       require_once($qs_part2 . ".php");
   }
   // 4.) else if page does not exist, go to 404 page
   else {
       require_once("404.php");
   }
?>


Everything is displayed properly, working all fine. The only issue is that because of the single-point entry through "index.php", all the CMS fields are displayed within one template in the admin panel (that template clearly links to "index.php", as seen when hovering over it --> see screenshot below).

For the sake of usability, I would like to have different templates for each of the files in the admin panel (e.g. "home", "about", "404", ...) instead of having all the fields for all the pages listed in one long list in one single template. But I do not know how that would be possible to do with a single point entry.

The single-point entry is important to me, though, because the redirect functionality I need seems impossible to do within the .htaccess alone. That's because I have a few different redirects happening:
1.) if "/", go to "home.php"
2.) if "/en", go to "home.php" as well
3.) if "/en/home", go to "home.php" as well
4.) else, go to "404.php"

Thank you for your support.

All the best,

andi

Attachments

Hi,

Would the following post help? -
viewtopic.php?f=2&t=7731#p12323

Do let me know.
Thank you, KK, for your reply.

I tried to follow the advice in the post but I keep getting "ERROR: Tag "pages": masterpage 'c_home.php' not found" whenever I try to load "home.php".

What I did is:
1. I created a file named "c_home.php"
Code: Select all
<?php require_once( "../couch/cms.php" ); ?>

<cms:template title="C_Home" executable="0">
    <cms:editable name="home_h2" type="text" />
</cms:template>

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


2. I added this code inside the <main></main> of "home.php":
Code: Select all
<cms:pages masterpage="c_home.php">
      <h1><cms:show home_h2 /></h1>
</cms:pages>


3. I loaded "c_home.php" in the browser - seems to load fine - it also shows correctly in the admin panel.

4. I tried to load "home.php" but it doesn't load - instead it prints "ERROR: Tag "pages": masterpage 'c_home.php' not found".

Just to clarify: The file "c_home.php" resides in the same folder as "home.php". Both files contain the two PHP lines for enabling CouchCMS. I even turned off the redirect in the .htaccess file.

What could I be doing wrong to cause such an error?
Since the templates are located within a folder (as opposed to directly in the root), their names as specified in 'masterpage' param needs to reflect that (doesn't matter that both are located in the same folder).

So, for example, if the folder is 'abc', the 'masterpage' would become this -
Code: Select all
<cms:pages masterpage="abc/c_home.php">
..
</cms:pages>

TIP: Hover your mouse on the template's entry in the sidebar of the admin-panel - you'll see a tooltip showing what you need to use as its 'masterpage' value.

Hope this helps.
Wow, that really was the key to making it work! Now, everything is working just like I wanted it from the beginning.
Very neat and straightforward, and I was able to keep the single-point entry through "index.php". Excellent!

Thank you so much, KK!
You are welcome :)
6 posts Page 1 of 1
cron