Problems, need help? Have a tip or advice? Post it here.
9 posts Page 1 of 1
Hello,

is it possible to show the content of the first page (e.g. index.php?p=1) when the address of the template (index.php) is called? Of course you could change the .htaccess to do that, but I prefer a solution with couchcms.
Thank you!

Best regards
MGMT
Hi and welcome :)

There are two ways of doing so. In the 'home-view' of index.php we could either -
1. Use the (yet undocumented) 'masquerade' tag e.g.
Code: Select all
<cms:masquerade "http://www.yoursite.com/index.php?p=1" />

2. or use the 'pages' tag to fetch in the first page (either by id or by name) and then display its content e.g.
Code: Select all
<cms:pages masterpage='index.php' id='1'>
   ..all variables of first page can be accessed here..
</cms:pages>
or
<cms:pages masterpage='index.php' page_name='name_of_first_page'>
   ..all variables of first page can be accessed here..
</cms:pages>

Hope this helps.
Do let me know. Thanks.
Hi and thank you for your answer!

I got the "masquerade" version to work, but I prefer a way without a real redirect.
The user who is calling index.php should stay on index.php.
Can you please tell me how the "pages" tag works exactly?

EDIT: Ok I understand how it works now. You have to put the pages tag around the variables in the body section of the html. thanks!

E.g. my index.php looks like that:
Code: Select all
<?php require_once( 'couch/cms.php' );?>
<cms:template title='Landingpage' clonable='1'>

  <cms:editable name='big_image'
    show_preview='1'
    quality='100'
    type='image'
  />
 
</cms:template>
<html>
<head>
  <title>Landingpage</title>
</head>
<body>
  <div id="bigpic_box" style="background: url('<cms:show big_image />') no-repeat scroll 0 0 #fff;" >
  </div>
</body>
</html>
<?php COUCH::invoke(); ?>


Where do I have to put the pages tag?

Thank you so much for your help!

Best regards
MGMT
Hi,

The 'masquerade' tag does not change the URL but it requires cURL library to be available on your server. In case cURL is not available, the tag falls back upon redirection. It seems that is what is happening in your case.

Anyways, we still have the 'pages' method.
In your template above, you have a single editable region named 'big_image' and this is the portion where its value is used
Code: Select all
  <div id="bigpic_box" style="background: url('<cms:show big_image />') no-repeat scroll 0 0 #fff;" >
  </div>
</body>

We need to differentiate in the code as to whether we are dealing with a cloned page (e.g. index.php?p=12) or the home page (e.g. index.php). this is how we do it -
Code: Select all
<cms:if k_is_page >
  <div id="bigpic_box" style="background: url('<cms:show big_image />') no-repeat scroll 0 0 #fff;" >
  </div>
<cms:else />
   <!-- we are showing the home page -->
</cms:if>

What you wish is that while dealing with the home page, we show contents of the first cloned page. This can be done by making the following changes to the code above
Code: Select all
<cms:if k_is_page >
  <div id="bigpic_box" style="background: url('<cms:show big_image />') no-repeat scroll 0 0 #fff;" >
  </div>
<cms:else />
   <!-- we are showing the home page -->
   <cms:pages masterpage='index.php' id='1'>
     <!-- we have content of the first page here to use -->
     <div id="bigpic_box" style="background: url('<cms:show big_image />') no-repeat scroll 0 0 #fff;" >
   </cms:pages>
</cms:if>

Of course you need to specify the id of the first page (or better still use the 'page_name' parameter and specify the name of the first cloned page).

Hope this helps.
Hi KK,

thanks. Yes I forgot to enable cURL, now it's working with the masquerade tag.
However I found that the site loads faster if you use the masterpage tag solution, so I'm using this one at the moment.

Thanks for your help!

Best regards
MGMT
Ok, i have a new problem regarding this topic because now I have enabled Pretty URLs.

My solution was like that:

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

<cms:template title='Landingpage' clonable='1'>
/* here I defined all of my 10 editable regions */
</cms:template>

<?php if (!isset($_GET['p'])) { ?>
<cms:pages masterpage='index.php' id='1'>
<?php } ?>
<html>
/*here comes the html including the 10 show tags */
</html>
<?php if (!isset($_GET['p'])) { ?>
</cms:pages>
<?php } ?>
<?php COUCH::invoke(); ?>

This solution worked really well without pretty urls. But with pretty urls enabled, of course there won't be any Get-Parameters set for the pages.

So I tried the following code:

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

<cms:template title='Landingpage' clonable='1'>
/* here I defined all of my 10 editable regions */
</cms:template>

<cms:if k_is_page == '0' >
<cms:pages masterpage='index.php' id='1'>
</cms:if>
<html>
/*here comes the html including the 10 show tags */
</html>
<cms:if k_is_page == '0' >
</cms:pages>
</cms:if>
<?php COUCH::invoke(); ?>


Unfortunately I get this error message:
Code: Select all
ERROR! Closing tag "if" has no matching opening tag (line: 58 char: 1459)

So it seems that I can't nest the tags like I expected.
It would be very much code if I needed to place the masterpage tags around every show tag.
Do you know a better solution (besides the masquerade tag)?

Thank you so much!

MGMT
Nesting of tags is not required. Try this -
Code: Select all
<?php require_once( 'couch/cms.php' );?>

<cms:template title='Landingpage' clonable='1'>
/* here I defined all of my 10 editable regions */
</cms:template>

<cms:if k_is_list >
   <cms:pages masterpage='index.php' id='1'>
      <html>
      /*here comes the html including the 10 show tags */
      </html>
   </cms:pages>
</cms:if>

<?php COUCH::invoke(); ?>
No, that doesn't work, because now there won't be any html shown if "k_is_list" is false.
To make it clear: I put all my html between the if tags.
That's the reason why I tried to nest the tags.
I just illustrated the way to make available the page's data in a list-view.
You can use the else clause to handle the other view (I had given a snippet doing this in an earlier reply in this thread).
I'll do that again -
Code: Select all
<?php require_once( 'couch/cms.php' );?>

<cms:template title='Landingpage' clonable='1'>
/* here I defined all of my 10 editable regions */
</cms:template>

<cms:if k_is_list >
   <cms:pages masterpage='index.php' id='1'>
   <html>
      /*here comes the html including the 10 show tags */
   </html>     
   </cms:pages>
<cms:else />
   <html>
      /*here comes the html including the 10 show tags */
   </html>       
</cms:if>

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

If avoid duplication of HTML, you can save this part -
Code: Select all
<html>
   /*here comes the html including the 10 show tags */
</html>

in a snippet (say named 'index.html') and then the code becomes
Code: Select all
<?php require_once( 'couch/cms.php' );?>

<cms:template title='Landingpage' clonable='1'>
/* here I defined all of my 10 editable regions */
</cms:template>

<cms:if k_is_list >
   <cms:pages masterpage='index.php' id='1'>
         <cms:embed 'index.html' />
   </cms:pages>
<cms:else />
   <cms:embed 'index.html' />       
</cms:if>

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

Hope this helps.
9 posts Page 1 of 1
cron