Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hello Couch enthusiasts! I'm having a real problem with getting the var used to set an image link to let go of the var it just set iterating through the remaining <pages> and I have no clue why.

There are 3 choices user can make: artist(2), album(1), track(0) - these trigger their own template and respective editables.
If 'track.php's editable 'image' field which is called 'nca_trk_sngl_elem_img' is empty, then I want to show the image for the album for which it is related (from type='relation' editable).
Code: Select all
<cms:set crnt_crd_stk_sbj_plyr_sdbr_img="<cms:thumbnail nca_alb_inf_img />" "global" />

This part works as expected.

If nca_trk_sngl_elem_img field has info, I set the var to that field:
Code: Select all
<cms:set crnt_crd_stk_sbj_plyr_sdbr_img="<cms:show nca_trk_sngl_elem_img />"  />

This also works as expected.

But what happens is that once the var is set due to the track.php's image field being populated (as opposed to empty), this image continues on for every image link for the rest of the <pages> iterations with empty track.php image fields (that would normally go thru the <related_pages> path). If track.php's image editable field is empty, it doesn't follow the "if" conditional of being empty, the image that populated from track.php's image editable will persist. If track.php's field is populated on the new iteration, then the var sets to that field, but now, that image will persist.

I have tried <cms:if nca_trk_sngl_elem_img=""> and <cms:if "<cms:not nca_trk_sngl_elem_img />" > (as you see below) and <cms:if "<cms:not_empty nca_trk_sngl_elem_img />" > when checking track.php's image editable being empty.
and I get the same results each time.

Am I not asking if the image field is empty in the right way? Is there another way to check 'empty' fields?

Code: Select all

                <cms:pages masterpage=crnt_crd_stk_sbj_plyr_sdbr limit='8'  >
                  <li>
                    <a href="<cms:show k_page_link />" class="d-flex align-items-center">

                  <cms:if nca_crd_stk_sbj_plyr_sdbr_opt='2'>
                      <cms:set crnt_crd_stk_sbj_plyr_sdbr_img="<cms:thumbnail nca_arts_elem_img width='150' />" />
                  <cms:else_if nca_crd_stk_sbj_plyr_sdbr_opt='1' />
                      <cms:set crnt_crd_stk_sbj_plyr_sdbr_img="<cms:thumbnail nca_alb_inf_img width='150' />" />
                  <cms:else />
                      <cms:if "<cms:not nca_trk_sngl_elem_img />" >
                          <cms:related_pages 'nca_trk_elem_track_albums_rel' >
                              <cms:set crnt_crd_stk_sbj_plyr_sdbr_img="<cms:thumbnail nca_alb_inf_img />" "global" />
                          </cms:related_pages>
                      <cms:else />
                           <cms:set crnt_crd_stk_sbj_plyr_sdbr_img="<cms:show nca_trk_sngl_elem_img />"  />
                      </cms:if>
                  </cms:if>
                      <img src="<cms:show crnt_crd_stk_sbj_plyr_sdbr_img />" alt="<cms:show k_page_title /> Image" class="img-fluid mr-2">
                      <div class="podcaster">
                        <span class="d-block"><cms:show k_page_title /></span>
                        <span class="small">
                          <cms:if nca_crd_stk_sbj_plyr_sdbr_opt='2'>
                              <cms:show nca_arts_elem_pg_rol />
                          <cms:else_if nca_crd_stk_sbj_plyr_sdbr_opt='1' />
                              Rel: <cms:show nca_alb_inf_rel_dt />
                          <cms:else />   
                              <cms:related_pages 'nca_trk_elem_track_albums_rel'>
                                <cms:show k_page_title />
                              </cms:related_pages>
                          </cms:if>               
                        </span>
                      </div>
                    </a>
                  </li>
                </cms:pages>




Happy to hear any feedback on this.
UPDATE:

I changed the scope of the related pages to "parent" and I empty the var right before </pages> and that seems to work, with the exception for the initial iteration on load when it needs to pull from reverse_pages.

As I <cms:show the var after every line (see code below), I see that it shows the correct link (empty) as it starts the iteration, it takes the correct path and goes thru the reverse pages and get set to the correct image link, but after it exits <cms:related_pages, even before it exits the 'if' condition, the var is erased

INTERESTINGLY ENOUGH all subsequent iterations run through the conditional correctly whether or not pulling from reverse_pages. They show to start off with an empty var, and go through the correct paths and set the var correctly. The var holds true throughout and then clears at the end.

I feel like I'm missing something about related_pages or checking for an empty image field (or both?) and my workarounds are band-aids. What am I doing wrong?

Code: Select all

                <cms:pages masterpage=crnt_crd_stk_sbj_plyr_sdbr limit='8'  >
                  <li>
                    <a href="<cms:show k_page_link />" class="d-flex align-items-center">
PreIF <cms:show crnt_crd_stk_sbj_plyr_sdbr_img /><br>
                  <cms:if nca_crd_stk_sbj_plyr_sdbr_opt='2'>
                      <cms:set crnt_crd_stk_sbj_plyr_sdbr_img="<cms:thumbnail nca_arts_elem_img width='150' />" />
                  <cms:else_if nca_crd_stk_sbj_plyr_sdbr_opt='1' />
                      <cms:set crnt_crd_stk_sbj_plyr_sdbr_img="<cms:thumbnail nca_alb_inf_img width='150' />" />
                  <cms:else />
                      <cms:if nca_trk_sngl_elem_img >
                        <cms:set crnt_crd_stk_sbj_plyr_sdbr_img="<cms:show nca_trk_sngl_elem_img />"  />IMG link <cms:show crnt_crd_stk_sbj_plyr_sdbr_img />
                      <cms:else />
                        <cms:related_pages 'nca_trk_elem_track_albums_rel' >
                            <cms:set crnt_crd_stk_sbj_plyr_sdbr_img="<cms:thumbnail nca_alb_inf_img />" "parent" />2IMG link <cms:show crnt_crd_stk_sbj_plyr_sdbr_img />
                        </cms:related_pages>
                        POST rEL link <cms:show crnt_crd_stk_sbj_plyr_sdbr_img />
                      </cms:if>
                  </cms:if>
                      <img src="<cms:show crnt_crd_stk_sbj_plyr_sdbr_img />" alt="<cms:show k_page_title /> Image" class="img-fluid mr-2">
                      <div class="podcaster">
                        <span class="d-block"><cms:show k_page_title /></span>
                        <span class="small">
                          <cms:if nca_crd_stk_sbj_plyr_sdbr_opt='2'>
                              <cms:show nca_arts_elem_pg_rol />
                          <cms:else_if nca_crd_stk_sbj_plyr_sdbr_opt='1' />
                              Rel: <cms:show nca_alb_inf_rel_dt />
                          <cms:else />   
                              <cms:related_pages 'nca_trk_elem_track_albums_rel'>
                                <cms:show k_page_title />
                              </cms:related_pages>
                          </cms:if>               
                        </span>
                      </div>
                    </a>
                  </li>
                   <cms:set crnt_crd_stk_sbj_plyr_sdbr_img=""/>
                </cms:pages>



Declaring "parent" populates the parent variable. If that parent is not declared previously, then.. you guess it!

Try this:
Code: Select all
<cms:pages masterpage=crnt_crd_stk_sbj_plyr_sdbr limit='8'  >
    <cms:set crnt_crd_stk_sbj_plyr_sdbr_img = '' /><cms:ignore><!-- preparing dynamic image for the track --></cms:ignore>
                  <li>
...
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
3 posts Page 1 of 1