Search
Other Articles Anywhere questions
Forum

Can I use if-else in foreach structures?

Tsung Ching Lee's Avatar Tsung Ching Lee
I create a structure to list articles with joomla subform field [category-group]
this is my code
{article}
    {if category-docs-limited != "0"}
          {foreach data="category-group"}
             <div class="doc__group --[row:group-level:value]">
                  <h2 class="docs__title">[row:category-title]</h2>
                  <div class="docs__list">
                   {articles category="article" tags="<?php echo $services;?> && [row:category-alias:value] && <?php echo $doctype;?>" limit="<?php echo $doclimited;?>" ordering="<?php echo $ordering;?> <?php echo $ordering_direction;?>"}
                        <div>[link class="docs__item"][title][/link]</div>
                        {articles-else}
                        <div class="docs__empty">尚無文章</div>
                        {/articles}
                    {articles category="article" tags="<?php echo $services;?> && [row:category-alias:value] && <?php echo $doctype;?>" limit="1"}
                         {if total-no-limit >= <?php echo $doclimited;?>}
                            <a href="[row:category-more-url:value]" class="services-doc__more">看全部
                                [total-no-limit]篇文章
                                 <i class="fa-regular fa-arrow-right"></i>
                             </a>
                          {/if}
                     {/articles}
                 </div>
              </div>
           {/foreach}
     {else}
          ...
   {/if}
{/article}

I want to use if structure inside the foreach structure.
{if row:group-level:value = 'child'}
<h3>This is Child category title</h3>
{else}
<h2>This is category title</h2>
{/if}

But it not work.
Peter van Westen's Avatar Peter van Westen ADMIN
It is not possible to nest {if} structures in Articles Anywhere code.
Maybe try and move the first if to a filter in the {article} tag:
{article}
    {if category-docs-limited != "0"}
To:
{article id="current" category-docs-limited!="0"}
Please post a rating at the Joomla! Extensions Directory
Tsung Ching Lee's Avatar Tsung Ching Lee
I try to remove first {if} structures
but if I place {if row:group-level:value = 'child'}{/if} after {foreach data="category-group"}
like this a.cl.ly/QwuXndBg
but it not work a.cl.ly/6quXzGXv
Peter van Westen's Avatar Peter van Westen ADMIN
The things you are trying are only available in the Pro version.
You do not have a subscription for Advanced Module Manager connected to your current account.
If you have a subscription connected to a different account, please use that to ask your questions.
Please post a rating at the Joomla! Extensions Directory
Tsung Ching Lee's Avatar Tsung Ching Lee
OK I have renewed my subscription.
and I use pro version in my site.
Peter van Westen's Avatar Peter van Westen ADMIN
And is all working as it should now?
Please post a rating at the Joomla! Extensions Directory
Tsung Ching Lee's Avatar Tsung Ching Lee

I've been using the Pro version for development for many years, and my subscription was due after this discussion was posted. Today, I completed the purchase request with my company and came back to continue to ask questions.
So, from the beginning of using the Pro version, I've never been able to accomplish according to the previous method.

screen record
share.zight.com/xQuQN005

{article id="<?php echo $id;?>" category-docs-limited!="0"} not work

www.dropbox.com/scl/fi/rm7hq8ni93dwrqf3t...xmc7jcy7wfesgaf&dl=0
this is the article php file, and this is the version can run. But can not use if inside foreach.
Peter van Westen's Avatar Peter van Westen ADMIN
Try:
{article id="<?php echo $id;?>" category-docs-limited="!0"}
Please post a rating at the Joomla! Extensions Directory
Tsung Ching Lee's Avatar Tsung Ching Lee
Still empty output. and I checked my field value. a.cl.ly/9Zu4LNmw
Tsung Ching Lee's Avatar Tsung Ching Lee
this is the frontend testing page
support.amt.org.tw/tw/vital-crm/faq
Confidential information:
(hidden)
Peter van Westen's Avatar Peter van Westen ADMIN
Very difficult to see what is going on on a site where the layout is broken, together with the Chinese text.

Can you simplify this on a clean install with simple test articles and fields, and break it down to the bare minimum?
And use the {article tag syntax in a normal article (not in a template override) so we can eliminate any external factors.
Please post a rating at the Joomla! Extensions Directory
Tsung Ching Lee's Avatar Tsung Ching Lee
Hi
I have create a simple sample here
support.amt.org.tw/tw/?view=article&id=74&catid=29
backend
support.amt.org.tw/administrator/index.p...le&layout=edit&id=74

From this sample I place the if condition inside {article} tag,sample1 can't output any subform fields.


Sample2 I remove if country condition, only use foreach to show the subform fields. it's prove the subform fields can output.


Sample3 I put the if condition under article tag and wrap the foreach subform field. it's prove the country condition can work.


Sample4 I put the if condition "level" --> {if row:level:value="1"} under foreach loop. it seems subform field can not use as if condition.



Question1: can subform field use as if condition?
Question2: can I use if condition inside article tag?
Peter van Westen's Avatar Peter van Westen ADMIN
You should be able to add filters on custom fields in the {articles} tag.

Please not a difference in syntax when using negative filters in the {article} or {articles} tags, and when using them in the {if} tags:
{articles key="!value"}
vs
{if key!="value"}

Also, be careful with adding whitespace around the = in the filters. That can cause issues with the syntax.

Going by your use of the if statements here, to check what heading tag to output, why not do:
<h[row:level:value]> ... </h[row:level:value]>
Please post a rating at the Joomla! Extensions Directory
Tsung Ching Lee's Avatar Tsung Ching Lee
thank you Peter
I use subform inside h tag. it's ok.
But I change {article id="74" country!="0"} to {artilces id="74" country="!0"}

support.amt.org.tw/tw/?view=article&id=75&catid=29
Still output nothing.

BTW So currently the subform fields cannot be used as a if condition? Is it possible to do this in the future?
Peter van Westen's Avatar Peter van Westen ADMIN
BTW So currently the subform fields cannot be used as a if condition? Is it possible to do this in the future?
No, that won't be possible.

Are you able to reproduce the filter issue on a clean Joomla setup with minimal data and fields?
If so: Can you give me (super) admin and (s)ftp access so I can take a look?
And tell me on what url I can see/reproduce the issue.
You can use the 'Confidential information' button in the forum editor to hide sensitive information.
Please post a rating at the Joomla! Extensions Directory
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription