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

I've been working on a big project lately, so I am posting a lot questions.
Hopefully, these questions will also help some other people that might have the same ones.

Here's my question :

Is it possible to use custom_field in a masterpage element to filter the content of it, based on a relation editable in that page?
Here's what I have.
I am using a JS calendar, and displaying the events based on what is inside the "contrats.php" page. It works fine without the custom_field filter, but won't display anything with it. Here's my code (part of it):

Code: Select all
events: [
      <cms:pages masterpage='proposals.php' custom_field='contact_dropdown=<cms:show k_page_title/>'>
        {
          title: '<cms:show k_page_title/>',
          start: '<cms:show start_date_test/>',
          color: '#FF0000'
        },
      </cms:pages>
      ]


Inside the "proposals.php" page, there's a field where the user can select which contact is linked to this proposal. Contacts are added via another clonable page. It acts a bit like some sort of address book.

What am I doing wrong?

Is that even possible to link a relation field in a "custom_field" property to filter data of a page?

Thanks!

(sorry english is not my native language and this one was hard to explain)
Hi,

You asked -
Is it possible to use custom_field .. to filter the content.. based on a relation editable in that page?

Yes. You'll find full documentation of it with several examples here - viewtopic.php?f=5&t=8581 (under heading "2. Enhanced cms:pages tag").

So, assuming your 'proposals.php' template has within itself a relation field defined named 'contact_dropdown', following should find all proposals related to a contact page named 'john-doe' -
Code: Select all
<cms:pages masterpage='proposals.php' custom_field="contact_dropdown=john-doe">
    ..
</cms:pages>

Please notice that I am using page_name and *not* page_title. This is important - we can only use page_names or ids when querying a relation field.

So if, instead of the hard-coded page_name, we were to use a variable as in your example the code would now become -
Code: Select all
<cms:pages masterpage='proposals.php' custom_field="contact_dropdown=<cms:show k_page_name />">
    ..
</cms:pages>

As you can see, compared to your original code, I have made two rectifications -
a. used k_page_name instead of k_page_title
b. used double-quotes to set 'custom_field' value. This is important else the nested Couch tags within it won't get executed.

OK, that should fix the iteration part. Try the code above in a standalone fashion (i.e. without trying to generate JSON with it) to confirm that it is fetching the proposals as expected.

Now for the JSON part.
Your code actually has a problem with it - the JSON is malformed.
The last item in your events array will have a comma which is not acceptable to JSON.

To fix that, add a <cms:not k_paginated_bottom/> check as shown below.
Your final code should be something like this -
Code: Select all
{
    "events": [
        <cms:pages masterpage='proposals.php' custom_field="contact_dropdown=<cms:show k_page_name />">
            {
                title: "<cms:show k_page_title/>",
                start: "<cms:show start_date_test/>",
                color: "#FF0000"
            }<cms:if "<cms:not k_paginated_bottom/>">,</cms:if>
        </cms:pages>
    ]
}

For more examples of generating JSON, please see
viewtopic.php?f=4&t=9207
viewtopic.php?f=8&t=8602

Hope it helps.
Thank you so much KK!
It worked perfectly.

Couch CMS deserves to be way more popular. This CMS is so powerful!

Thanks again
You are welcome :) I am glad you found Couch useful.
4 posts Page 1 of 1
cron