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

I could use a hint on something. I have a homepage that consists only of one template with pages, no list or home view. I want to display a certain page called 'home' when a list view or home view is being called for. So far, I have used this:

Code: Select all
<cms:if k_is_page >
  <html>
  //the entire page view
  </html>
<cms:else />
  <cms:redirect url="<cms:link masterpage='index.php' page='home' />" />
</cms:if>


I have two problems with this. The first is that some hosts really don't like 301 redirects and cause trouble (Internal Server error 500). The other one is that I think doing this is incredibly not elegant.

Another way I tried to achieve this was the following. Which, alas does not work because it attempts to write a system variable:

Code: Select all
<cms:if k_is_page == '0'>
  <cms set k_page_name = 'home' />
</cms:if>


Can someone give me a hint on how to implement this?
Hi :)

The redirect method is the staple in such cases, so I think your method is fine.

some hosts really don't like 301 redirects and cause trouble (Internal Server error 500)
301/302 redirects are an integral part of WWW (pages inevitably change locations over time and this method is what makes it possible without SEO penalties). So, I beg to differ but I don't see why any host would have any problem with redirects.

Anyway, as an alternative, you can simply output the contents of the 'home' page on the list-view using the cms:masquerade tag -
Code: Select all
<cms:if k_is_list>
   <cms:masquerade "<cms:link masterpage='index.php' page='home' />" />
</cms:if>

The cms:masquerade tag requires 'curl' to be available on your host (usually is). In case it does not work (will fallback to redirect), you can do the following -
Code: Select all
<cms:if k_is_list>
   <cms:pages masterpage='index.php' page_name='home'>
      .. all variables from 'home' are available here. Display them as you wish ..
   </cms:pages>
</cms:if>

You can use the same HTML in there as you do in the page-view.
To avoid duplication of HTML code, you can place that in a snippet which can be reused at the two locations e.g. as follows -
Code: Select all
<cms:if k_is_page >
   <cms:embed 'my_page.html' />
<cms:else />
   <cms:pages masterpage='index.php' page_name='home'>
      <cms:embed 'my_page.html' />
   </cms:pages>
</cms:if>

As you can see, in a page-view, the selected page is automatically in context. In the list-view, we use cms:pages tag to explicitly bring a specific page into context. The HTML used for the display remains the same.

Hope it helps.
2 posts Page 1 of 1