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

I am wondering whether this is even possible. I am trying to use a 2X <cms:set> variables as a custom fields in <cms:pages>

Code: Select all
<cms:set curr_time="<cms:date format='H:i' />" />
<cms:set post_time="<cms:date alt_date format='H:i' />" />

<cms:pages masterpage='example-page.php' custom_field="<cms:show curr_time /> > <cms:show post_time />">


Code: Select all
<cms:date alt_date />
is the only one in the masterpage.

If I post the following code in
Code: Select all
<cms:pages masterpage='example-page.php' custom_field="<cms:date alt_date format='H:i' /> > <cms:show post_time />">


It also doesn't work, I get the following error

ERROR: Custom Field "21:36" does not exist in 'example-page.php'


Hopefully someone can help.
If you try expanding your code -
Code: Select all
custom_field="<cms:date alt_date format='H:i' /> > <cms:show post_time />"

- it will, e.g., evaluate to this
Code: Select all
custom_field="21:36 > 18:42"

The left side of the statement (21:36) is not the 'name' of a custom field (i.e. a <cms:editable> region).

We can use the 'custom_field' parameter with only bonafide editable regions. e.g. following should be ok (assuming 'custom_field' is indeed a region defined in the template) -
Code: Select all
custom_field="some_field > 18:42"

Hope this answers your query.
Thanks for the reply KK.

I think I'm getting a little confused. I am trying to show only pages that when the custom field expression is true and it will show the results of the page, but the original editable region for "some_field" is in a different format. ie full datetime, that is why I was trying to change the format.

Code: Select all
custom_field="21:36 > 18:42"


Is exactly what i'm trying to determine. I was originally trying to format the set fields as a number, so that it is 2136 > 1842, but again the original field is a datetime.

I could use an if else statement, but the data I'm trying to get is repeating for an XML, so in theory an if else statement will only show the first result not all the results.

Hope this makes sense.
All dates are stored internally by Couch in a single format ('Y-m-d H:i:s' format e.g. 2019-05-30 21:35:54).

Assuming it is a 'datetime' region you are trying to filter the pages listing on, the correct way would be to format the second value (right hand side) of your expression to match the mentioned format e.g.
Code: Select all
<cms:set curr_time="<cms:date format='Y-m-d H:i:s' />" />
<cms:pages masterpage='example-page.php' custom_field="post_time < <cms:show curr_time />">

The code above assumes that your datetime region is named 'post_time' and will try to fetch pages with this region having a value less than the current time.

Hope this helps.
..
4 posts Page 1 of 1