Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hi,

I'm looking for the best way to create a bit of code that shows the latest post if it has a value in a specific editable field. (I'm building a bibliographical site for an academic author - the user can create both empty items in their bibliography, and ones where they include the text for display on the site. To keep things simple, all entries are made on the same cloned page, and the user uses different editable regions for different types of entry, i.e. a book, a magazine article, or some loose notes they want to share.)

This bit should display the latest single cloned page, IF that page has ANY value in the editable region (called "tekst").
Trying to use the custom field parameter in cms:pages for it, but I'm not sure what the syntax would be for "this editable field should not be empty". Also, if I take limit='1', does it only look at the first page, or does it output a single result that matches the condition?

Code: Select all
<cms:pages limit="1" custom_field="tekst!=''">

<a href="<cms:show k_page_link/>"><cms:show k_page_title/></a> 

</cms:pages>


The above doesn't seem to work (I've tried variations with different quotes).


Relatedly, just wondering: is there a way to produce results from different cloned pages as a single list, but have them ordered depending on date (or any other sorting criterion), but in an overarching manner? A cms:meta-pages, so to speak...

Many thanks.
Code: Select all
<cms:pages orderby='publish_date' order='desc' limit='1' return_sql='0' custom_field='text!==' >
    <cms:show k_page_title />
</cms:pages>


Note that text!== translates into request search_value != '' while text!= goes to search_value NOT LIKE '%%'. Big difference, I know. When in doubt, I always refer to generated SQL to know what exactly is going on under the hood with param return_sql. Good luck!
trendoman wrote:
Code: Select all
<cms:pages orderby='publish_date' order='desc' limit='1' return_sql='0' custom_field='text!==' >
    <cms:show k_page_title />
</cms:pages>


Note that text!== translates into request search_value != '' while text!= goes to search_value NOT LIKE '%%'. Big difference, I know. When in doubt, I always refer to generated SQL to know what exactly is going on under the hood with param return_sql. Good luck!


Thank you!

Oh yes, that return_sql is good to know, will definitely put that to use elsewhere.
Thijs wrote: Thank you!

Oh yes, that return_sql is good to know, will definitely put that to use elsewhere.

You are welcome, dear colleague. Actually this conversation even inspired me to think about a quick addon for cms:pages to put SQL statement to console for review, it could be a param console_sql='1' which will not stop cms:pages to work, as it does now with return_sql='1'.
P.S. Done :)
2020-05-27_174858.png
cms:pages console_sql='1'
2020-05-27_174858.png (9.45 KiB) Viewed 1061 times
4 posts Page 1 of 1