Rendering a custom field 'type=media' somehow...

Search
Other Bug Reports questions
Forum

Rendering a custom field 'type=media' somehow messes up code execution

Ton van Loon's Avatar Ton van Loon
When I want to show the contents of a custom media field in a relative complex code << using {if} and/or nested if's with {article-nested id="[id]"} >> somehow the code exection gets messed up.

Config:
- Joomla 4.0.3
- Article Anywhere v11.1.1-dev2165300

Situation:
- Based on conditions, I want to show images from custom media fields in a known article (id=64 / title= instellingen)
- Conditions:
-- status:
- 0: evaluate dates to determine 1 2 or 3
- 1: outcome = rehearsing
- 2: outcome = uitvoering
- 3: outcome = uitgevoerd
- 4: outcome = gecancelled
-- if status = 0 -> evaluate 2 dates: << datum-eerste-uitvoering && datum-laatste-uitvoering >> to determine 1 2 or 3
- Status 1 2 3 and 4 each have its own image file in its own custom media field [rehearsing] [uitvoering] [uitgevoerd] [gecancelled] in config-article id=64

When I only use a TEXTUAL outcome, the above evaluatrion goes right. But when I want a IMAGE outcome, it goes wrong and it seems to mess up the article-referencing

It wrote test cases, to find out what is happening.

TEST CODE 1: straight forward referencing
This article: test referencing bij id en by title / 67

Title: {article}[title]{/article}
ID: {article}[id]{/article}

Other article: instellingen / 64

Title (ref by ID): {article id="64"}[title]{/article}
ID (ref by title): {article title="instellingen"}[id]{/article}

Outcome: as expected.

TESTCODE 2: more complex
{article}

INPUT:

today is: 11-11-2021 ( 11 november 2021)
first-date is: [datum-eerste-uitvoering]
last-date is: [datum-laatste-uitvoering]
Status-value: [status:value]

Checking referencing config-article "instellingen" / id=64:
config-article-ID (ref by title):  {article title="instellingen"}[id]{/article}
config-article-TITLE (ref by id): {article id="64"}[title]{/article}

Checking 'contents of dummy-text-field' from config-article "instellingen" / id=64:
dummy-text-field (ref'd by title=instellingen):  {article title="instellingen"}[dummy-text-field]{/article}
dummy-text-field (ref'd by id=64): {article id="64"}[dummy-text-field]{/article}

Checking 'status Image URL' from config-article "instellingen" / id=64:
 a) Referencing by ID:
{if status='1'}{article id="64" }[rehearsing:url]{/article}{/if}
{if status='2'}{article id="64"}[uitvoering:url]{/article}{/if}
{if status='3'}{article id="64"}[uitgevoerd:url]{/article}{/if}
{if status='4'}{article id="64"}[gecancelled:url]{/article}{/if}

b) Referencing by TITLE:
{if status='1'}{article title="instellingen" }[rehearsing:url]{/article}{/if}
{if status='2'}{article title="instellingen"}[uitvoering:url]{/article}{/if}
{if status='3'}{article title="instellingen"}[uitgevoerd:url]{/article}{/if}
{if status='4'}{article title="instellingen"}[gecancelled:url]{/article}{/if}

{/article}

OUTPUT:

{article}
{if status:value='0'} 
{article-nested id="[id]"}

{if datum-eerste-uitvoering > date('today') && datum-laatste-uitvoering > date('today') }BOTH IN FUTURE {/if}
{if datum-eerste-uitvoering < date('today') && datum-laatste-uitvoering > date('today') }IN BETWEEN {/if}
{if datum-eerste-uitvoering < date('today') && datum-laatste-uitvoering < date('today') }BOTH IN PAST {/if}

{/article-nested} 
{/if}
{/article}

TEST CASES TEXTUAL OUTPUT

A 1. Test with textual-output: case status = 0  ( -> evaluate dates 'datum-eerste-uitvoering'  && 'datum-laatste-uitvoering')

{article}
{if status:value='0'} 
{article-nested id="[id]"}

{if datum-eerste-uitvoering > date('today') && datum-laatste-uitvoering > date('today') }REHEARSING-date-evaluation{/if}
{if datum-eerste-uitvoering < date('today') && datum-laatste-uitvoering > date('today') }UITVOERING-date-evaluation {/if}
{if datum-eerste-uitvoering < date('today') && datum-laatste-uitvoering < date('today') }UITGEVOERD-date-evaluation {/if}

{/article-nested} 
{/if}
{/article}


A 2. Test with textual-output: case status != 0 ( -> evaluate 'set' status =1/2/3/4)

{article}
{if status:value!='0' }
{article-nested id="[id]"}

{if status='1'}REHEARSING-set-status{/if}
{if status='2'}UITVOERING-set-status{/if}
{if status='3'}UITGEVOERD-set-status{/if}
{if status='4'}CANCELLED-set-status{/if}

{/article-nested} 
{/if}
{/article}


TEST CASES IMAGE OUTPUT

B 1. Test with IMAGE-output: case status = 0

{article}

{if status:value='0'} 
{article-nested id="[id]"}

{if datum-eerste-uitvoering > date('today') && datum-laatste-uitvoering > date('today') }{article id="64"}[rehearsing]{/article}{/if}
{if datum-eerste-uitvoering < date('today') && datum-laatste-uitvoering > date('today') }{article id="64"}[uitvoering]{/if}
{if datum-eerste-uitvoering < date('today') && datum-laatste-uitvoering < date('today') }{article id="64"}[uitgevoerd]{/if}

{/article-nested} 
{/if}
{/article}

B 2. Test with IMAGE-output: case status != 0

{article}
{if status:value!='0' }
{article-nested id="[id]"}

{if status='1'}{article id="64"}[rehearsing]{/article}{/if}
{if status='2'}{article id="64"}[uitvoering]{/article}{/if}
{if status='3'}{article id="64"}[uitgevoerd]{/article}{/if}
{if status='4'}{article id="64"}[gecancelled]{/article}{/if}

{/article-nested} 
{/if}
{/article}

OUTCOME

See: sta.vanloon.net/index.php/tst

Or see screen shots:

1. https://imgur.com/CxwOKbY
2. https://imgur.com/DmZR9eJ
Peter van Westen's Avatar Peter van Westen ADMIN
If you want to nest article tags, you need to give them an alias.
See: docs4.regularlabs.com/articlesanywhere/g...ther/nested-articles
Please post a rating at the Joomla! Extensions Directory
Ton van Loon's Avatar Ton van Loon
I’m afraid I don’t understand you / the documentation quite. Can you give me a short pseudo code example related to my case (evaluating 2 scenarios)?
Peter van Westen's Avatar Peter van Westen ADMIN
{article}
{if status}
{article-nested id="[id]"}

{if status=1}{article-whatever id="64"}[rehearsing]{/article-whatever}
{elseif status=2}{article-whatever id="64"}[uitvoering]{/article-whatever}
{elseif status=3}{article-whatever id="64"}[uitgevoerd]{/article-whatever}
{elseif status=4}{article-whatever id="64"}[gecancelled]{/article-whatever}
{/if}

{/article-nested} 
{/if}
{/article}

Also, I don't see the need for using the extra article-nested here with the surrounding if.
Why not do this?
{article}
{if status=1}{article-whatever id="64"}[rehearsing]{/article-whatever}
{elseif status=2}{article-whatever id="64"}[uitvoering]{/article-whatever}
{elseif status=3}{article-whatever id="64"}[uitgevoerd]{/article-whatever}
{elseif status=4}{article-whatever id="64"}[gecancelled]{/article-whatever}
{/if}
{/article}
Please post a rating at the Joomla! Extensions Directory
Ton van Loon's Avatar Ton van Loon
Thank you very much. I understand now.

So whenever I intend to nest an {article}-statement within an other {article}-statement:
{article} 
  {article}[somefield]{/article}
{/article}

I should write
{article} 
  {article-somealiasname}[somefield]{/article-somealiasname}
{/article}

And thank you for the extra refactoring.
Peter van Westen's Avatar Peter van Westen ADMIN
Yes, correct.
Please post a rating at the Joomla! Extensions Directory
You can only post on this forum if you log in