Forum for discussing general topics related to Couch.
10 posts Page 1 of 1
Hi everybody!

I like the idea a lot and would love to use it for a small project. now this project is a small single page app.

Instead of distinct pages i have some divs which are hidden/shown by jquery. this divs represent the "pages". now i could easy set up a template and have 6 richtext editables in there. but that would be just to much for my customer, since there is quite a bit of text in each div. i want to seperate those into templates, so the pages are represented as templates in the backend. the problem is, it looks like there can be only 1 template per file.

how can i have 1 file with multiple templates included?
Hi and welcome Novalis :)

What appears to be a 'single' page on the front-end need not be the same in the back-end.
It is perfectly OK to use multiple templates (one for each section of the 'single' page) in the back-end and then use the output from all these templates to 'compose' a 'single' page.

I'd go about doing it this way -
1. We'll use 'index.php' as the main template i.e. the only one accessed from the front-end.
2. Create a template each for every constituent section e.g. about-us.php, contact.php etc.
Make sure to set executable='0' in the cms:template tag of these templates as they won't be accessible directly via URLs from the front-end.
3. Define the required editable regions in each template.
The back-end now will show all the 'sections' as individual templates in the sidebar.

The values entered in the individual templates can be consolidated on index.php by using the 'masterpage' parameter of cms:pages tag. For example -
Code: Select all
<h2>About Us<h2>
<cms:pages masterpage='about-us.php' >
   <!-- all editable regions defined in about-us.php available here -->
</cms:pages>

<h2>Contact Us<h2>
<cms:pages masterpage='contact.php' >
   <!-- all editable regions defined in contact.php available here -->
</cms:pages>

Hope this helps.
this sounds perfect. just... doing it, i get an error :

Error: masterpage: "who-are-we.php" not found. Error: masterpage: "staff.php" not found. Error: masterpage: "clients.php" not found.

As you can see i changed the about.php from the tutorial to have multiple templates.
in the page tag documentation is says:
Code: Select all
<cms:pages masterpage='blog.php'></cms:pages>
This example would fetch all pages cloned from blog.php.

is the cloned thing the problem?
i am a step further. the files are found after i loaded the pages initialy once by browser. i wonder that this works, since i put the executable='0' in there.

but the main problem is now, the content of the template is not showing
got it now

in the page tag i was missing the:
Code: Select all
<cms:show test1 />


for some reason i thougt the regions will show automaticly

thx very much,
great help
Glad you got it working :)
i wonder that this works, since i put the executable='0' in there.
It works only for the super-admins as otherwise they won't be able to register a new non-executable template. The general public will get a 404 error.
Hello, this is my first post so I just want to say thank you so much for this amazing back-end tool. CouchCMS suits my needs perfectly and I may be purchasing a license soon to support the authors. Now, with that said...

I'm attempting to include multiple templates on a 'single' webpage as well but am struggling to pull it together on the front-end. I'm basically an amateur. I believe I understand your ideology, KK:
1. We'll use 'index.php' as the main template i.e. the only one accessed from the front-end.
2. Create a template each for every constituent section e.g. about-us.php, contact.php etc.
Make sure to set executable='0' in the cms:template tag of these templates as they won't be accessible directly via URLs from the front-end.
3. Define the required editable regions in each template.
The back-end now will show all the 'sections' as individual templates in the sidebar.


First, does "template" explicitly refer to anyfile.php or the instance of <cms:template> in a php file?

Second, do I use <?php require_once('.../cms.php'); ?> on each constituent php file or only index.php? And, in this circumstance of multiple templates, does/can the index file have any instance of <cms:template> or is that only done on the constituents, e.g. index_part1.php, index_part2.php?

I'm sure there's even more that I'm missing but any advice would be greatly appreciated.
Hello and welcome, abirduphigh :)

I'll try to clarify your doubts -
First, does "template" explicitly refer to anyfile.php or the instance of <cms:template> in a php file?
Template, in Couch parlance, is always a .php file. To be more specific, a template is a Couch managed .php file that is accessed through the browser explicitly using its name.

For example, a typical site will consist of several such templates e.g. index.php, blog.php, contact.php etc.
These files are accessible by their names e.g. as
http://www.yoursite.com/index.php
http://www.yoursite.com/blog.php
http://www.yoursite.com/contact.php
and hence are the 'templates'.

If you go through our tutorial (http://www.couchcms.com/docs/tutorials/portfolio-site/) this will become clear.

You'll also find there that a template can contain within itself embedded snippets e.g. blog.php internally could contain 'header.php' and 'footer.php'. These snippets are also files but are not considered templates as you'll never access them directly as e.g. http://www.yoursite.com/snippets/header.php

Moving further -
Every template (and only template) contains the
<?php require_once( 'couch/cms.php' ); ?>
<?php COUCH::invoke(); ?>
statements.

So, in our example, index.php. blog.php and contact.php, all three will have the two PHP statements. But header.php and footer.php will not.

Once we place the above statements in a template and visit it once as super-admin, Couch registers it and shows it in the admin-panel's sidebar.

So, another hallmark of a template is that it appears in the admin-panel's sidebar.

Hopefully that clears things up a little bit.
Now I'll address the specific confusion that you have.

I'll continue with the example site I mentioned above.
So we have index.php. blog.php and contact.php and since these are accessible as URLs, these are our templates.

Which means each of the three file has the <?php require_once( 'couch/cms.php' ); ?>..<?php COUCH::invoke(); ?> statement in it.

Which again means that the three appear as distinct entries in the admin-panel sidebar.

Now if we were to define editable regions (<cms:editable>) in the three templates, we'll see those in the admin-panel (clicking, for example, on contact in sidebar will reveal all editable regions defined in it).

I think all the above said points should be clear enough.

Now consider what happens if we do this -
If we edit the 'index.php' template, and place the following statements in it -
Code: Select all
<cms:pages masterpage='blog.php' limit='5'>
   <h3><cms:show k_page_title /><h3>
</cms:pages>

<cms:pages masterpage='contact.php' limit='1>
   <h3><cms:show k_page_title /><h3>
</cms:pages>

What will happen is - when we access the index template (as for example http://www.yoursite.com/index.php or simply http://www.yoursite.com/), it shows us the data from the blog and contact template.

Do you get the point above?
In Couch we can show data belonging to any template (e.g. blog.php) on any other template (e.g. in index.php above).

So although blog.php and contact.php are templates, just like index.php, we can always show their data on index.php (or, conversely, we can show data from index.php on contact.php if we so want).

We can use this property to create single-page sites.

In fact, the code we placed in index.php above has already turned our site into a single-page application (as a single template index.php is showing data from all other templates).

The only hitch above could be that the blog and contact templates can be accessed directly via URLs e.g. http://www.yoursite.com/contact.php, which won't be desirable as we are creating a single page site.

Though we cannot completely prevent a template from being accessed through URL (as that is the very definition of a template) what we can do is prevent non-admins (i.e. normal visitors) from doing so.

To do this, we edit blog.php and contact.php and add the following code within them
<cms:template executable='0'>

</cms:template>

Doing this makes them off-limit to general public.

The cms:template tag above can be placed in any template (and only template) and is used to set certain properties of the the template e.g. the following if placed in some template will make the template clonable, commentable and make it appear as 'Products' in the admin-panel sidebar -
Code: Select all
<cms:template title='Products' clonable='1' commentable='1'>

</cms:template>


I hope this would make the concept behind single-page site clear to you.
Please let me know if this helped.

Thanks.
Thank you, KK! You have been immeasurably generous and helpful. I think I understand these concepts much more now; I got my site to work the way I'd like thanks to you. I have indeed followed much of the tutorials, up through most of the Portfolio section. They are fantastic!

My situation is that I have a multi-page site in which I'd like the contents of the 'Homepage' (index.php) to simply be separated into multiple templates in the Admin Panel. Even with groups, managing all of the content of the Hompage on a single template in the admin panel proved too unwieldy.

Therefore, I've created a separate template for the jquery image slider, nivo-slider, (which integrated very nicely with this CMS, btw) and my client can manage both the image slider options as well as the general content of the page on separate template tabs in the back-end for relief.

Let me reiterate, that you have been incredibly helpful. I'm grateful that I stumbled upon this CMS!
You are welcome :)
I am glad I could help.
10 posts Page 1 of 1