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

I am working on sort of a profile directory for a business.
In the admin, I've added a checkbox that let us choose if the profile is available on PAGE-A.php (for example), and/or on PAGE-B.php.
They can be on both if both checkboxes are checked.
Right now, it's not working correctly. I used the CSV import script to import all my profiles, and by default, all profiles are appearing on PAGE-A.php. But now, I only have few profiles that needs to appear on both. So when I go in these clonable pages profile, I check both checkboxes, hit "SAVE", but nothing changes on the front-end.

What I have noticed is that if I create a new profile (after all the profiles being imported), and select both checkboxes, or one or the other, it works. So it looks like only the profiles that have been imported are not following the checkbox thing rule.

Here's my code on the PAGE-B.php (the page where only few profiles should appear...that is not working right now) :

Code: Select all
<cms:pages masterpage='profile.php' paginate='1' limit='8' >

              <cms:each profile_titles as='titles'>

                  <cms:set my_category="<cms:show titles  />" />

                  <cms:if "<cms:not_empty my_category />" >

                        <cms:if my_category = 'Animateur' >
                        <div class="conferenciers-card">
                          <a href="<cms:show k_page_link />"><div class="profile-card-photo" style="background-image:url('<cms:show profile_image />')"></div></a>
                          <a href="<cms:show k_page_link />" class="profile-card-title"><cms:show profile_prenom /> <cms:show profile_nom /></a>
                          <div class="separator profile"></div>
                          <div class="profile-card-text"><cms:show profile_soustitre /></div><a href="<cms:show k_page_link />" class="w-button profile-card-button">En savoir plus</a>
                        </div>
                      </cms:if>

                  </cms:if>
                </cms:each>

                    </cms:pages >


On the PAGE-A.php, it's the same code, except with :
Code: Select all
<cms:if my_category = 'Conférencier-Formateur' >

instead of
Code: Select all
<cms:if my_category = 'Animateur' >


Like I said, it works when I create new profiles, but it doesn't work if I edit current ones.
Is that a cache thing?

Thanks!
Hi,

I don't think it is a cache issue (you may disable the cache temporarily if you wish).
To trouleshoot the issue, we need to check what values are being fetched by cms:pages. Perhaps while importing the data the values got modified in some manner.

To do that, print out the values as the script goes through them to know what is happening as follows -
Code: Select all
<cms:pages masterpage='profile.php' paginate='1' limit='8' >
    profile_titles: <cms:show profile_titles /><br />
       
    <cms:each profile_titles as='titles'>
        titles: <cms:show titles /><br />
       
        <cms:set my_category="<cms:show titles  />" />
        my_category: <cms:show my_category /><br />
       
        <cms:if "<cms:not_empty my_category />" >
            <cms:show my_category /> is not empty. <br />
           
            <cms:if my_category = 'Animateur' >
                <div class="conferenciers-card">
                <a href="<cms:show k_page_link />"><div class="profile-card-photo" style="background-image:url('<cms:show profile_image />')"></div></a>
                <a href="<cms:show k_page_link />" class="profile-card-title"><cms:show profile_prenom /> <cms:show profile_nom /></a>
                <div class="separator profile"></div>
                <div class="profile-card-text"><cms:show profile_soustitre /></div><a href="<cms:show k_page_link />" class="w-button profile-card-button">En savoir plus</a>
                </div>
            <cms:else />
                my_category is not 'Animateur'.
            </cms:if>
        </cms:if>
    </cms:each>

</cms:pages >

Please test it out on pages where you think the category is supposed to be 'Animateur'. The code will show if that is so (you'll the messages more clearly in 'view-source' of the page).

Hope it helps.
Hi KK,

Thanks a lot.
I've pasted the code you have entered, and that's what comes out on the front-end :

Code: Select all
profile_titles: 
profile_titles: Conférencier-Formateur
titles: Conférencier-Formateur
my_category: Conférencier-Formateur
Conférencier-Formateur is not empty.
my_category is not 'Animateur'. profile_titles: Conférencier-Formateur
titles: Conférencier-Formateur
my_category: Conférencier-Formateur
Conférencier-Formateur is not empty.
my_category is not 'Animateur'. profile_titles: Conférencier-Formateur
titles: Conférencier-Formateur
my_category: Conférencier-Formateur
Conférencier-Formateur is not empty.
my_category is not 'Animateur'. profile_titles: Conférencier-Formateur
titles: Conférencier-Formateur
my_category: Conférencier-Formateur
Conférencier-Formateur is not empty.
my_category is not 'Animateur'. profile_titles: Conférencier-Formateur
titles: Conférencier-Formateur
my_category: Conférencier-Formateur
Conférencier-Formateur is not empty.
my_category is not 'Animateur'. profile_titles: Conférencier-Formateur
titles: Conférencier-Formateur
my_category: Conférencier-Formateur
Conférencier-Formateur is not empty.
my_category is not 'Animateur'. profile_titles: Conférencier-Formateur
titles: Conférencier-Formateur
my_category: Conférencier-Formateur
Conférencier-Formateur is not empty.
my_category is not 'Animateur'.


"Conférencier-Formateur" being the other checkbox that you can check.
So I guess it doesn't find any profiles with "Animateur" checked?

There's supposed to have 2 profiles with Animateur checked.
What's wrong?
There's supposed to have 2 profiles with Animateur checked.
What's wrong?
I am not sure but perhaps the values were not imported correctly (maybe the syntax used was not right).

For now, I think you should manually set the second value on those pages.

Hope it helps.
Well I'm already trying to manually go into the profiles that needs to be both "Animateur" and "Conferencier-Formateur", and check the "Animateur" checkbox, but it's doing nothing.

There's over 100 profiles. 95% of them are "Conferencier-Formateur", and the rest needs to be "Animateur". That would take a lot of time to go into each profiles, and check the boxes manually for every single one of them.

Any idea on how to fix this without doing that?

Thanks!
Looks strange. Anyways, to bulk-update data use this:

Code: Select all

<cms:pages masterpage='your-template.php' skip_custom_fields='1' >


   <cms:db_persist
        _invalidate_cache="1" _mode="edit"
        _masterpage    = 'your-template.php'
        _page_id         = k_page_id
        profile_titles    = 'Conférencier-Formateur'                   
        >
      <cms:if k_error >
        <cms:log "<cms:concat k_error ' - ' k_page_name '<br>'  />"  file="error.html" />
      </cms:if>
    </cms:db_persist>


</cms:pages>



Code above may not work for various reasons, but it is covered with logging.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Hi Anton,

What is the use of this code?
I'm not sure I understand.

Thank you
@trendoman's code, if you place it in a template and run the template, will loop through the pages of the specified masterpage and set the checkboxes to the specified value. It is basically the same that you would have used while importing the pages.

Anyway, the problem is that even if you are manually setting the values it seems to be doing nothing -
I'm already trying to manually go into the profiles that needs to be both "Animateur" and "Conferencier-Formateur", and check the "Animateur" checkbox, but it's doing nothing.

This needs to be investigated. If your setup happens to be online please get me FTP+Couch access to it and I'll try to see if I can spot the reason.
Hi KK,

Thanks for your reply.
I will send you a PM with the FTP info as soon as I can. Thanks a lot.
Solved.

Pagination & limit were used in cms:pages which fetched all pages without conditions. Inside the cms:pages conditional limited output to zero elements, that's why nothing was displayed in html (although correctly fetched). Custom_field parameter for cms:pages solved this with fetching pages prefiltered by custom editable, enabling correct use of paginator and display of target pages.

Update:
Ok, here is a bit simpler explanation.

Definitions:
Initially there are 2 checkboxes:

Code: Select all
<cms:editable
  name="is_conferencier"
  label="Profile Conferencier?" desc="Cochez si oui"
  opt_values='oui'
  type='checkbox'
/>
<cms:editable
  name="is_animateur"
  label="Profile Animateur?" desc="Cochez si oui"
  opt_values='oui'
  type='checkbox'
/>


The task is to show only pages where is_animateur == 'oui' (checked).

Simplified code which is correct, but doesn't do the expected (and does the unexpected):

Code: Select all
<cms:pages masterpage='profile.php' paginate='1' limit='8' orderby="page_title" order="asc" >

   <cms:if is_animateur >
     <cms:show profile />
   </cms:if>

</cms:pages>



Now, what happenes here is <cms:pages> normally serves what's ordered, but with limit and pagination can show only first 8 pages.

It happened that there were no A(nimateur)-pages in the first 8 batch - so we see empty html and may wrongly think the code doesn't work. It is even worse for debug, actually, because there is no <cms:paginator /> and no other way to see that code above is correctly serving all un-filtered pages. Just empty html with no clues :(

My first step is to change limit='8' to '0' and instantly feel better. All A-profiles are showing. The same effect could be achieved by placing <cms:dump /> - it will show information about all 8 served pages. It will also tell us that code actually works fine.
Next, we place a paginator and introduce
custom_field="is_animateur==oui"
to <cms:pages> which solves this task completely. Also now can place limit='8' back.

As a moral to the story - we have to always carefully fetch pre-filtered data before pagination. Any conditionals performed over already fetched data can result in seemingly empty results.

Hope it helps.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
10 posts Page 1 of 1
cron