Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
Not sure why this has to be so complicated. I was able to follow the tutorial to setup Couch to create my articles and display the individual articles. Using Couch to display a list of these articles has been a nightmare.

My individual articles are at http://www.mydomain.com/html/news_articles.php?p=113 and I obviously want a list of these articles to appear at http://www.mydomain.com/html/news_articles.php

Using the tutorials I am told to embed the page that displays the list using:

<cms:else />
<cms:embed 'articles.php' />
</cms:if>

articles.php is the page I have created to view the article list. When I try to visit http://www.mydomain.com/html/news_articles.php to view the list I get an error saying the file articles.php cannot be found in the /snippets directory - so I added articles.php to the /snippets directory in my Couch install and the page loads. Awesome that works ... but now we arrive at the main reason I need help.

When I go to http://www.mydomain.com/html/news_articles.php I see my template and code that is a part of articles.php my template loads but I get a new Couch error:

Error: masterpage: "/news_articles.php" not found.

I've tried changing the path of "/news_articles.php" to everything I can think of to match the actual location of "/news_articles.php" which is http://www.mydomain.com/html/news_articles.php but all Couch does is print the same error.

So I'm spinning in circles here. I don't understand what I am doing wrong. All I want is a list od the articles. The date and article title. I don't need a preview of the article on the listing page- very simple. But not so simple with Couch. Can anyone help me make this process a little more straightforward please? I'm assuming once I get this issue resolved the articles will be listed.

Also, when I am typing articles and I click on source and try to embed YouTube code to display a video in my article Couch outputs the HTML code as text. Why??? How do I get around that?
Hey Dustin,

Welcome to our forums:)
I am so sorry you are finding the listing part difficult.
But don't worry - I'll try and take you step-by-step through the process and once you get the hang of it, I am sure, you'll find it pretty simple.

So let us begin.
I can see from your post (and the mail you send) that splitting the news section into two physical files (one for page-view and another list-view) is complicating things for you.

If you don't want to split your code into multiple files, you absolutely don't have to. We can place everything in a single file and it will work just the same. Let us do just that.
We'll work with only the main template 'news_articles.php' - forget the other one for now.

If you change the following existing code in 'news_articles.php'
Code: Select all
<cms:else />
   <cms:embed 'articles.php' />
</cms:if>

to
Code: Select all
<cms:else />
   <h1>List of pages</h1>
</cms:if>

and then visit http://www.mydomain.com/html/news_articles.php, you'll see the heading 'List of pages'. No actual listing of pages yet (that is next) but the point is that we are handling the list-view using a single template. No embeds involved.
If we add Couch code that'll list the pages between the <cms:else /> and </cms:if> tags above, you'll get the listing.

Let us do that now.
The actual code for listing pages in Couch is very simple and will always involve the cms:pages tag. Modify the code to add the new code so that it now becomes the following
Code: Select all
[code]<cms:else />
    <h1>List of pages</h1>
   
    <cms:pages>
        <h3><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></h3>
        <!-- all other variables of the page available here for showing -->
    </cms:pages>
   
</cms:if>[/code]

Visit the template and you should see a listing of names of all the cloned pages. Of course, you have all the data from editable regions available here as variables, so you can use any markup you wish to show the pages.
You might also want to show only a limited number of pages and add pagination etc.

That is all covered in the tutorial.
The main point of my post is that the above cms:pages loop is the only essential thing for listing - you can use the tag's parameters to fine-tune the listing.

I know, if you are using the code from our tutorial, the above listing wont have any styling applied (no CSS, JS) etc. but I'll come to that. Let us stay for now with the essentials.

In the cms:pages code we added above, notice we did not specify which template to list the pages of. That is ok as, if not specified, Couch will use the template the code is on as default which is fine here.

If we wanted, however, to list pages from a different template, we'll have to use the 'masterpage' parameter. So, although the 'masterpage' parameter is totally redundant in our case, we'll still go ahead and use it. Please modify the code to make it -
Code: Select all
<cms:else />
    <h1>List of pages</h1>
   
    <cms:pages masterpage='news_articles.php'>
        <h3><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></h3>
        <!-- all other variables of the page available here for showing -->
    </cms:pages>
   
</cms:if>

Notice how I am using the name of our template as the masterpage.
View in browser again.
The listing should look exactly the way as before.

If, however, we receive any error here (as you have been getting) we'll have to scrutinize the template name we provided (in your post I see that it contains a leading '/' which is wrong).

Normally a template's name is the same as its physical file (e.g. 'news_articles.php'). However, if the template is within subfolder(s), the paths also becomes a part of the name.
Let me explain -
assume that 'news_articles.php' is within a folder named 'html' - its template name now becomes 'html/news_articles.php'.
If it were to be in 'html/new', the name will now become 'html/new/news_articles.php'.

TIP:
If in doubt about a template's name, please hover your mouse on the template's entry in admin-panel's sidebar (while logged-in as super-admin of course) and you'll see a tooltip showing the actual name.


I think you' be able to debug the template name problem now.

OK, let us resume the discussion to take the multi file problem you find complex :)

Cut away all the code we have in our template between the <cms:else /> and </cms:if> to make it -
Code: Select all
<cms:else />

</cms:if>

Create a file (name it anything - I am assuming it is 'my_snippet.html') and put it in Couch 'snippets' folder.
Now paste the content we cut away from the main template into it. The 'my_snippet.html' will now have the following contents -
Code: Select all
<h1>List of pages</h1>

<cms:pages masterpage='news_articles.php'>
    <h3><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></h3>
    <!-- all other variables of the page available here for showing -->
</cms:pages>

In the main template now, modify the empty else block to make it
Code: Select all
<cms:else />
    <cms:embed 'my_snippet.html' />
</cms:if>

Visit the template again and you should see that the listing shows exactly the same as before.

So, the point I am trying to bring home here is that any code embedded in a snippet is exactly the same as its contents being physically placed in the original template.

Please think over what I said above. In your case, if the embedded snippet is throwing an error, you would have got the same error had the code been in a single template.

OK, so if there is no difference why do we use snippets?
1. It makes the code on the main template look cleaner.
In our case, the embedded code is only a few lines but if it were to extend to several hundred it'd look unwieldy - mind you it will work on the main template also - it'll just look bulky.

2. Reuse.
If you want to use the same code in several templates (e.g. this could be code for menu or footer etc.), it is a huge time-saver to put the code in a single snippet and embed it in all the different templates. In event of any changes required, you'll have to make it at just one place and it will reflect on all templates.

So now I think you have enough data to troubleshoot the original problem (using your older snippet).

It has been a long post but hope I was able to dispel the few misunderstandings that you had.

Please let me know if you still have any problems. PM me (or email me) the involved templates and I'll have a look.

Thanks.
2 posts Page 1 of 1