Articles Field

[image-intro width="40"] ?

1 year 7 months ago #83346

Marc's Avatar Marc

Hi Peter,

I hope you are fine 🙂

In the Custom HTML of my Articles FIeld, I used to have something like this :
<img src="[image_intro]" alt="[title]" width="40px">

But the image is not physically resized of course.

In Articles Anywhere there is this syntax which is great :
[image-intro width="40"]

Could we somehow achieve the same result with Articles Field (directly or indirectly, now or in a later version) ?

1 year 7 months ago #83347

Peter van Westen's Avatar Peter van Westen Admin

You can use Articles Anywhere inside the Articles Field.

{article [id]}[image-intro width="40"]{/article}

1 year 7 months ago #83348

Peter van Westen's Avatar Peter van Westen Admin

You can even leave out the id, as it is the current article:

{article}[image-intro width="40"]{/article}

1 year 7 months ago #83350

Marc's Avatar Marc

Well, I have just tried

{article}[image-intro width="40"]{/article}
but it shows the intro image or the article itself, not the intro image of the article brought by "Articles Field"

Here is my code (for a local event of ours. It is called a JoomlaDay 😁)
It displays all Conferences :
{articles category="18"}
<div class="conf room-[salle output="value"] [slot output="value"]">           
<p>{tip title="[title]" content="[pitch]"}<strong>[link][title][/link]</strong>{/tip}</p>
[b]<p>[speakers]</p>[/b]
<small>check: [session-debut]</small>
</div>
{/articles}

Actually, [speakerss] is the Articles Field. And I need to display the intro-image of [speakers], not of the conference.

That is why the Custom HTML of the "Speakers" Custom Field of the type "Articles Field" is the following :
<img src="[image_intro]" alt="[title]" width="40px">&nbsp; <a href="[url]" >[title]</a><br />

So maybe there is a better way to achieve this all...

1 year 7 months ago #83351

Peter van Westen's Avatar Peter van Westen Admin

Ah, sorry, it does need the ID of course. As you want the data from the linked article, not the current.
So should be:

{article [id]}[image-intro width="40"]{/article}
Or:
{article [id]}[image-intro width="40"]&nbsp; [link][title][/link]{/article}

1 year 7 months ago #83353

Marc's Avatar Marc

Txs Peter.

I have just tested it, but again it displays the image-intro of the Conference (we loop on the Conferences)... and not of the Speaker which is the Article Field...

And as I loop on Conferences, I can not harcode some [id] of course

1 year 7 months ago #83358

Peter van Westen's Avatar Peter van Westen Admin

The [id] should output the ID of the speaker (linked article).
Is only the image incorrect? Or is other data output by data tags in the Articles Field correct?

1 year 7 months ago #83361

Marc's Avatar Marc

The [id] obviously outputs the id of the Conference since we loop on conference.
Therefore, what I get with your snippet is... the intro image of the Confence, not the one of the speaker.

Until know, I was displaying the speaker by calling the Article Field named "[speakers]"

Do you want the credentials to see for yourself (maybe easier that explaining here).

Confidential information:
(hidden)

1 year 7 months ago #83369

Peter van Westen's Avatar Peter van Westen Admin

I don't mean that you use that code in the snippet.
Use it in the (custom) layout of the Articles Field.

1 year 7 months ago #83370

Marc's Avatar Marc

oh gosh !
sorry for the misunderstanding.

This is very smart to use {article} in the Custom Field itself (or in an article itself).
I would never have thought of that...

As you can see on the link I sent yesterday, everything is fine now ! 🙂

Txs again Peter !

1 year 7 months ago #83375

Peter van Westen's Avatar Peter van Westen Admin

Happy the penny dropped 🙂

Yeah, you can now pretty much use all the extra power Articles Anywhere provides inside the Articles Fields.
This is also the reason I don't think it is necessary to extend what data tags Articles Field itself supports.

1 year 7 months ago #83376

Marc's Avatar Marc

That's why it is nice to hear you at a conference or to have a chat here... because even if I daresay that I know your extensions pretty well, everytime I discover new combinations/horizons...
... like using {articles} inside an article itself 🙂

Besides that, last year you gave me a trick to have 2 different layouts for the same Articles Field :
www.regularlabs.com/forum/articlesfield/...ts-for-example#78418

But now with J!3.9 and your new versions, would there be a more efficient way to achieve that ?
(as it is know, it is a bit tricky : writing 2 layouts in the same Custom HTML of the Articles Field, use Rereplacer to drop the one we don't need on the selected Menu Items, have the Plugins in the right order and last but not least have the right "scope" (article/body/...) for all the Rereplacer items)

Txs,

Marc

1 year 7 months ago #83377

Peter van Westen's Avatar Peter van Westen Admin

Joomla 3.9 supports different layouts for custom fields.
Articles Anywhere supports that too.
See: www.regularlabs.com/extensions/articlesa...a-tags-custom-fields

The whole documentation for Articles Anywhere has been rewritten a month or 2 ago. And new stuff has been added since.
So I advise you to read through it all 🙂

To show a custom field inside the content of the article itself, instead of using the very limited and confusing core {field} tags, you could use:

{article}[name-of-my-field]{/article}
And use all the available bells and whistles Articles Anywhere offers.

1 year 7 months ago #83378

Marc's Avatar Marc

I'll definitely check that !
Txs for the tip Peter 😎

But from the Documentation, I am not sure of one thing : in those Alternate Layouts for Custom Fields, can I simply insert the following string as I use them in Articles Anywhere ?

{article [id]}[image-intro width="40"]&nbsp; [link][title][/link]{/article}

1 year 7 months ago #83379

Peter van Westen's Avatar Peter van Westen Admin

In your field override (template) you probably have something like this at the top in the php part:

$field = $displayData['field'];
The $field->value will contain an array of ids.

So you can loop over that and output the different {article} tags.
Or use the {articles} (plural) field to output all articles at once:
{articles ids="<?php echo implode(',', $field->value)); ?>"}
   [image-intro width="40"]
   [link][title][/link]
{/articles}

1 year 7 months ago #83380

Marc's Avatar Marc

Excellent !
I'll definitely try that 🙂

Txs again for the Tools... and the Tips 😉

1 year 7 months ago #83381

Marc's Avatar Marc

Hi Peter,

We're almost there !
The Alternate Layout is created.
In Articles Anywhere, [speakers layout="other_layout_speaker"] does trigger.

But it seems that

<?php echo implode(',', $value); ?>
is empty and therefore when using {articles} in the alternate layout, it outputs ALL the existing articles I think.

Confidential information:
(hidden)


The full alternate layout is hereafter.
Have I missed something ?
<?php
defined('_JEXEC') or die;
if (!key_exists('field', $displayData))
{
	return;
}
$field = $displayData['field'];
$label = JText::_($field->label);
$value = $field->value;
$showLabel = $field->params->get('showlabel');
$labelClass = $field->params->get('label_render_class');
if ($value == '')
{
	return;
}
?>
Implode gives this : <?php echo implode(',', $value); ?><br />
{articles ids="<?php echo implode(',', $value); ?>"}
   [link][title][/link]
{/articles}

1 year 7 months ago #83382

Andrea Malalana's Avatar Andrea Malalana Moderator

Hey Marc,

Me and Peter talked about this and this is the solution we came up with.

First all, the override needs to be a value_layout="..." (instead of layout="..."), as we are creating an alternative output specific for the value of the custom field, not the whole field display. So:

[speakers value_layout="other_layout_speaker"]
See this for more details: www.regularlabs.com/extensions/articlesa...rrides-value-layouts

As far as the PHP code for the custom layout, try this:
<?php
defined('_JEXEC') or die;

if (empty($displayData['fields']))
{
	return;
}
$ids = [];
foreach ($displayData['fields'] as $field) {
	$ids[] = $field->value;
}
?>
{articles ids="<?php echo implode(',', $ids; ?>" separator=", "}
   [link][title][/link]
{/articles}

1 year 7 months ago #83383

Marc's Avatar Marc

Txs a lot Andy !

We must be very close, but there is maybe a bug in value_layout then.
Let me explain

First, a little detail (for those reading us on day) :
I corrected

{articles ids="<?php echo implode(',', $ids; ?>" separator=", "}
to
{articles ids="<?php echo implode(',', $ids); ?>" separator=", "}
(missing parenthesis)

So, now the point :

If I put simply "test" in the Alternate Layout PHP file and stick to the
[speaker layout="other"]
then the word "test" populates every conference. Great ! (it means that my alternate layout is correctly triggered)
But as soon as I put
[speaker value_layout="other"]
what I get is the Default Output defined within my Custom Field, not "test".
And finally, of course if I replace "test" by the PHP you gave me, I still get the default output.

So it acts as if value_layout would not trigger and instead just throw the default ouput (if I interpret this correctly).

Note : I can give you access if it is more convenient to test in real conditions 🙂

1 year 7 months ago #83384

Peter van Westen's Avatar Peter van Westen Admin

I think I lost track of what you are actually trying to do now.

The value_layout option in Articles Anywhere does not work on the Articles Field.
This is because the field itself is not a list of items.
When you have an Articles Field set to 'Show linked Articles', the field itself is just a toggle value between true and false.
Articles Field itself will then figure out what to display.

So if you use a value_layout on the custom field in Articles Anywhere, you override the field itself figuring out what to output, and you essentially (with Articles Field) only have a value true to play with. So pretty useless.

So we'll need to backtrack...

Can you explain in short what it is you are trying to do?
I believe you want 1 (Articles Field) field to be output in different ways in different situations/conditions, right?
Can you elaborate?