Hi guys, I'm using couchcms a lot and one tag that I always found very useful is <cms:pages> to list the pages or to get data from other pages. As I learned in the docs and here in this forum, pages tag can be very slow as it makes lots of queries and when you are logged. Also the couchcms won't cache when you are logged in and depending on your implementation, you'll get a very slow page-load while working on the content.
I also learned that <cms:get_custom_field> is faster as it is more straight foward, but sometimes (usually) I just need to get a field from all pages of a clonable template. Thinking of that, I created a "helper" that can do this in a much faster way and it's being very useful to me (I had a page that took 20 seconds to load, now it takes 600-800 ms)
I created a file "get-page-list.php" inside my include folder:
And when I need to get the page list I do this:
It will define a variable "arr_page_names" that I can loop and get only the field values I want:
It's not "pretty" but very effective. I looked at couchcms source code and this was the best solution I could find to get the list of clonable pages (with something around 50 entries) multiple times in a page without having performance issues.
Do anyone has a better idea to do this? Maybe something more "native"?
I also learned that <cms:get_custom_field> is faster as it is more straight foward, but sometimes (usually) I just need to get a field from all pages of a clonable template. Thinking of that, I created a "helper" that can do this in a much faster way and it's being very useful to me (I had a page that took 20 seconds to load, now it takes 600-800 ms)
I created a file "get-page-list.php" inside my include folder:
- Code: Select all
<cms:set arr_page_names="" "global" />
<cms:query sql="
select p.id, p.name
from <cms:php>echo K_TBL_TEMPLATES;</cms:php> p
where p.name='<cms:show template_name />'"
limit='1'>
<cms:set template_id=id "global" />
</cms:query>
<cms:query sql="
SELECT p.template_id, p.page_name
FROM <cms:php>echo K_TBL_PAGES;</cms:php> p
WHERE p.template_id='<cms:show template_id />'">
<cms:if arr_page_names == "">
<cms:set arr_page_names=page_name "global" />
<cms:else />
<cms:set arr_page_names="<cms:concat arr_page_names '|' page_name />" "global" />
</cms:if>
</cms:query>
And when I need to get the page list I do this:
- Code: Select all
<cms:set template_name="name_of_the_template.php" />
<cms:embed "get-page-list.php" />
It will define a variable "arr_page_names" that I can loop and get only the field values I want:
- Code: Select all
<cms:each arr_page_names>
<cms:get_custom_field var="field_name" page=item masterpage=template_name />
</cms:each>
It's not "pretty" but very effective. I looked at couchcms source code and this was the best solution I could find to get the list of clonable pages (with something around 50 entries) multiple times in a page without having performance issues.
Do anyone has a better idea to do this? Maybe something more "native"?