Forum for discussing general topics related to Couch.
4 posts Page 1 of 1
I've been through the docs and I've been through the tutorial and I'm still not happy with what I've come up with for one of my pages, and I'm hoping there's a better way.

I have a News page which lists news items - you could think of them as the same as blog items if you like. I want to give editors the ability to add and edit these news items. But they're only ever displayed in a list on this page - i.e., there's no single page version for each of them. What I've done so far is to create a clonable template, news-item.php, containing the editable regions. This allows users to enter and edit news items via the admin page. Meanwhile in my news.php page, I have a cms:pages tag with news-item.php as the masterpage, displaying the news items fields as I wish, in a list. I am also able to display a subset of the items in a different format on the home page, which is helpful.

This system works but it seems slightly unsatisfactory to me because of the way the editor interacts with the page. Having entered the details, they can click a View button to see the result (and similarly they can click the view icon while looking a listing of existing pages). But there is in fact nothing to view as such, as there is no single page view for this page. What I've done so far is to test 'k_is_page' for the news-item.php and if true, redirect to 'news.php' where the items are displayed in a list. This seems pretty kludgy to me, although I can live with it.

What I would like to know is:
a) is there a better way of doing this whole thing?
b) if not, is there a way of hiding the View buttons for this page?
a. please, share what is exactly that you want to implement. So far, your solution seems normal.
Edit: sometimes it's comfy to create a protected page and let users enter news with a simple data-bound form. Upon successful submit, a new cloned page is created. There is more to code to be able to edit those pages, but you can avoid that by activating 'inline edit' addon, so admin can edit news on front-end. The form to submit news can be also placed in the same news.php and made visible only for proper logged-in user.

b. there is a way to hide any element on the edit page with editable type='message'. It helps to inject anything right in the admin panel. The idea is to hide 'View' button with injected CSS style. Button has no special id yet, as you can check in browser with inspector.
echo '<a class="button" id="view-page" href="'. $link .'" target="_blank" onclick="this.blur();"><span>';

Above is a small modification to /couch/edit-pages.php, line 493. It should be enough to use with our editable. Paste the following definition to your template, where you want to hide the button.
Code: Select all
<cms:editable 
name='hide_view_page_button'
type='message'
><style>a#view-page {display:none }</style></cms:editable>

I just run it on my test page and it worked. Only left is Save button.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
This seems pretty kludgy to me,
Seems fine to me. Since there is no page-view, you are directing the editor to the right place to see the results.

As an alternative, you can implement a page-view only for the editor so that on clicking view she can see the result in an isolated way. Place the redirect for normal visitors in case they happen to stumble upon a page-view.

Example code could be -
Code: Select all
<cms:if k_is_page>
    <cms:if k_user_access_level ge '7' >
        ... place HTML here to show the page ..

    <cms:else />
        <cms:redirect k_template_link />
    </cms:if>
</cms:if>
Thanks, KK and Trendoman - I'll combine both your suggestions.
4 posts Page 1 of 1