Forum for discussing general topics related to Couch.
9 posts Page 1 of 1
Hello,
wondering if anyone can point me in the right direction as I seem to be going around in circles.

I have a one page site which uses the load-more ajax method from https://www.couchcms.com/forum/viewtopic.php?f=8&t=8963&p=31611&hilit=infinite#p31611

What I want to be able to do is load all pages upto a specific id when the page url # fragment is an id of an event.
so i think i need to be able to:-
- check if an id exists as page
- if it does, load all pages upto that id
- revert to the load-more behaviour


Not after a solution (though would happily accept one) just a nudge in the right direction as
cheers

EDIT: After looking around as much as i can, i think all i need to know is how to exit the pages tag when a condition is met? Not having much luck figuring it out...

EDIT2: maybe cms:abort is the way to go, willl have a play and see...
One way to list limited pages is to use stop_before parameter with date of the final post.
active topics, google
Free support is never free.. Donate!
@trendoman Saw that but can't quit figure out how to pass #fragment. would i somehow pass #fragment, check if page exists, if so get it publish_date, then do pages with stop_before set to publish_date + 1day?

really all i want to do is if there is a #fragment in url, and that # matches an id of a page (eg event407 in this example), then load all pages upto that id, then revert to the code below and the load-more scenario.

maybe an if/else to set global_events_limit to k_page_foldertotalpagecount or k_page_folderpagecount then abort after matching id, reseting global_event_limit to global variable.

either way I'm still stumped as to how to get #fragment. no problem with js side, just not sure how to pass it to couch.

could/should it be done with cms:func a la https://www.couchcms.com/forum/viewtopic.php?f=8&t=11368&p=32274&hilit=functions#p32274

Code: Select all
<section id="listEvents" class="b-contentItem--sub-1" >
    <cms:set global_events_limit = "<cms:get_custom_field 'events_visible' masterpage='c/templates/globals.php' />" scope='global' />
    <cms:pages masterpage="c/templates/event.php" paginate='1' limit=global_events_limit >
        <cms:if k_page_foldertitle >
            <cms:set folder_category=k_page_foldertitle />
        <cms:else />
            <cms:set folder_category='Uncategorised' />
        </cms:if>
        <section id="event<cms:show k_page_id />" class="l-grac__item" data-grac-modifier="events" data-grac-group="eventslist" data-grac-multi="true">
            <h2 class="l-grac__item-heading"><cms:show k_page_title /> &bull; <cms:date k_page_date format='jS M, y' /> &bull; <cms:show folder_category /></h2>
            <div data-id="Event<cms:show k_page_id />" class="l-eventsItem">
                <ul id='swiperEvent<cms:show k_page_id />' class='swiper swiper--events -carousel ' data-swiperId="event<cms:show k_page_id />">
                    <cms:reverse_related_pages 'slider_blog_img' masterpage='c/templates/slider.php' >
                        <li><img class="tns-img tns-lazy-img" src="" data-src="<cms:show gg_image />" alt="<cms:show k_folder_name />" title="<cms:show k_page_title />" /></li>
                    </cms:reverse_related_pages>
                </ul>
                <div class="l-eventsItem-body">
                    <cms:show blog_content />
                </div>
            </div>
        </section>
        <cms:if k_paginated_bottom>
            <cms:if k_paginator_required >
                <!-- Pagination -->
                <a href="#"
                    id="load-more-events"
                    class="b-btn -primary b-btn--load-more"
                    data-limt="<cms:show global_events_limit />"
                    data-curr="<cms:show k_current_page />"
                    data-totl="<cms:show k_total_pages />">
                    Load more&nbsp;&nbsp;[<cms:show k_current_page />/<cms:show k_total_pages />]
                </a>
                <!-- /pagination -->
            </cms:if>
        </cms:if>
    </cms:pages>
</section>
The task reminds me of Non-uniform pagination topic viewtopic.php?f=8&t=11426
Did you see it? Quoting @KK on that -
.. consider what happens if we wish to start the listing skipping 3 posts (perhaps sticky) *and* the first page shows 10 while the others show 50.
Not an implausible situation. We now have to use both 'offset' and 'adjust' in this case.
active topics, google
Free support is never free.. Donate!
@trendoman No but I'm going to have a look now... Ok had a look. Seems it answers the revert to load-more bit of my problem, but still searching for how to load the initial list upto my #fragment.
Thanks for the link, will keep hunting for the rest
You can send current anchor to background script via a new data-* attribute. data-hash = window.location.hash;
Then strip the hash symbol with anything - couch or php:
Code: Select all
<cms:set hash = "<cms:each var=anchor sep='#'><cms:if k_last_item><cms:show item /></cms:if></cms:each>" />
<cms:set hash = "<cms:php>echo ltrim('<cms:show anchor />', '#');</cms:php>" />
active topics, google
Free support is never free.. Donate!
@trendoman Thanks again, I very much appreciate your time. I'm still a little stumped though (brain not working well today maybe).

1 - User visits site via link such as mysite.com/#event999
2 - (#)event999 could be the id of a page, or someother link in site
3 - i can't figure out how to get 2. into couch
4 - i can get it in js and set it to a data-attribute, but on what
5 - wherever the data-attribute is stored how do i then read it on couch

I guess if i do an ajax load-to-hash function and call that on page load, with a load-to-hash.html (similar so load-more.html) i can do the logic in there.

That seems to make sense in my head, but will <cms:abort> exit <cms:pages> tag?
If so I could check if hash exists as page, if it does exist do <cms:pages> & abort after matching page is displayed.

then see what happens with the load-more ajax (possibly using the offset/adjust solution if necessary)

Does that sound in anyway plausible?
cheers
@trendoman Thanks for pointers; went back over tutorials/docs & got myself straight on various k_vars, tags, prettyURLs and the like. Am much clearer now about how everything fits together. Have site up & running & working well. Finally feeling like i know (a little) what i'm doing.
Next couch site well under way & making a lot more sense :)
Thanks again, gwil
You are welcome :) Thanks.
active topics, google
Free support is never free.. Donate!
9 posts Page 1 of 1

Who is online

In total there are 3 users online :: 0 registered, 0 hidden and 3 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 3 guests