Forum for discussing general topics related to Couch.
14 posts Page 1 of 2
I currently have a website set up to use Sequential ID for certain cloneable templates. How can I automatically make those IDs the URL for the generated pages (ex: website.com/page/87)?
The sequential IDs are used for images and I'd like to drop images in with the gallery feature without having to manually change the URLs.
URL like /page/87 is based on page's name, i.e. cloned page must have a name "87". I fired up your webpage from the profile and see that probably you have k_page_id automatically copied to the k_page_name, is that correct?

UPD: I remembered an experiment where I wanted the UID to appear in the k_page_name. One issue was that Couch UID editable gets its value after the page is created, so the formatted/unformatted uid value does not appear among the variables on a blank new page and can not be used during intial save process. I had this limitation overcomed by querying the database directly to get the new uid value. Then it became possible to use the received value in form's config to persist the page with desired name (number). So, as this kind of solution required a few competencies, I would love to know a simpler way, if that exists. It is definitely not available in Couch out of the box.

P.S. Please see PM about images on the page.

your best friends: github, StackOverflow, telegram
At the moment, page name creation is whatever the default for cloned pages is. I manually change the name/url to suit my desired convention (page count). I'm looking for a way to do this automatically upon page creation.
Automatic naming of pages is possible via tag <cms:persist> that is used within <cms:config_form_view> block. You will find some details about both in original topic viewtopic.php?f=5&t=10241

sterre wrote: At the moment, page name creation is whatever the default for cloned pages is. I manually change the name/url to suit my desired convention (page count). I'm looking for a way to do this automatically upon page creation.

your best friends: github, StackOverflow, telegram
I've managed to show the count/UID in the page name field for the URL, but it runs into the previously mentioned limitation of an unsaved page not having a count yet.
While it's nice that existing pages can have the URLs renamed in this fashion, I still don't have a solution to my initial goal of automatically getting a newly created page's count as its URL.

Since the count is sequential by design, is it possible to get n+1, where n is the previous page's count?
sterre wrote: Since the count is sequential by design, is it possible to get n+1, where n is the previous page's count?


It is a mistake; a page can be deleted and "previous" becomes not so previous anymore. ;)

your best friends: github, StackOverflow, telegram
Perhaps this kind of manipulation can also be done by processing the page being saved *twice*? -
first let Couch save it the standard way and then immediately after that edit the newly saved page and change it anyway that is desired (renaming it with count, e.g. as in your case).

If this sounds reasonable, one way of achieving it would be to override the full form that Couch uses while saving pages (@trendoman has a complete list at viewtopic.php?f=8&t=13119).
'Advanced theming' on viewtopic.php?f=5&t=10241 has details about it and viewtopic.php?f=2&t=10438&p=25693#p25696 has a real life example.

Most of the code mentioned in the last link above is already a part of Couch now so you only need to activate the 'sample' theme and copy 'couch/theme/_system/content_form.html' into 'couch/theme/sample' folder. To make Couch use this snippet for only one particular template, rename it by suffixing the template's name to it (as explained in the above-mentioned post e.g. if the template is 'service.php', the snippet should be named 'content_form_service-php.html').

And now we can play with the save process -
the original code immediately redirects after a successful save
Code: Select all
<cms:db_persist_form
    _invalidate_cache='1'
    _token=k_cur_token
/>

<cms:if k_success >
    <cms:if k_redirect_link >
        <cms:set_flash name='submit_success' value='1' />
        <cms:redirect k_redirect_link />
    </cms:if>
</cms:if>

We can try re-editing the newly saved page and renaming to something else e.g. as follows (here only adding a '-xxx'; you can device your own format) before the redirection -
Code: Select all
<cms:db_persist_form
    _invalidate_cache='1'
    _token=k_cur_token
/>

<cms:if k_success >
    <cms:if k_cur_form_mode eq 'create'>
        <!-- find newly created page and edit it -->
        <cms:pages masterpage=k_template_name id=k_last_insert_id show_future_entries='1' limit='1'>
            <cms:db_persist
                _masterpage=k_template_name
                _mode='edit'
                _page_id=k_page_id

                k_page_name="<cms:show k_page_name />-xxx"
                k_page_title="<cms:show k_page_title /> xxx"
            />
        </cms:pages>
    </cms:if>
   
    <cms:if k_redirect_link >
        <cms:set_flash name='submit_success' value='1' />
        <cms:redirect k_redirect_link />
    </cms:if>
</cms:if>

Does this help?
@KK, saving page *twice* is an amazing solution. It is useful for uploading and processing images in one click.

your best friends: github, StackOverflow, telegram
Glad you liked it @trendoman; hope @sterre finds it useful too.
There are indeed use-cases (such as the one you mentioned) where processing the new page twice could be the answer.
@kk
The "save twice" solution worked perfectly. Thank you so much! This opens up some other possibilities for streamlining things, too.
14 posts Page 1 of 2
cron