Articles Field

Custom HTML Output : how to have 2 different outputs for example ?

9 months 1 week ago #78363

Marc's Avatar Marc

Hi again Peter,

Working actively on the JoomlaDay website, making extensive use of Custom Fields as you will see 😉

For the Conferences articles, we have a Speaker 'Article Field'.
It is great that we can use Custom HTML Output so that we can for example inject Picture and Name of speaker with link.

But what if on some pages we want that Custom HTML Output and on some other pages we would need another output (say just the Name to make it simple, or the Name and some other Custom Fields of the Speaker).
Would there be some direct (or even indirect) way to get that ?

Txs,

Marc

9 months 1 week ago #78366

Peter van Westen's Avatar Peter van Westen Admin

You can't do that with Articles Field itself.
I have no direct solution for that.

I guess this would require custom php coding.

9 months 1 week ago #78367

Marc's Avatar Marc

Even an indirect solution would be fine.

A bit like when you play with ReReplacer to intercept something in order to have like
[speaker 1] for layout 1
[speaker 2] for layout 2

9 months 1 week ago #78368

Peter van Westen's Avatar Peter van Westen Admin

Yeah, you could do something with ReReplacer.
Make sure the Articles Field outputs the data for both, like:

<!-- Speaker Layout 1 -->
...
<!-- /Speaker Layout 1 -->
<!-- Speaker Layout 2 -->
...
<!-- /Speaker Layout 2 -->
Then in ReReplacer you can remove one on whatever assignment you set up, and remove the other on all other pages.

Search:
<\!-- Speaker Layout 1 -->(.*?)<\!-- /Speaker Layout 1 -->\s*<\!-- Speaker Layout 2 -->(.*?)<\!-- /Speaker Layout 2 -->
Replace with:
\1
Else:
\2

9 months 1 week ago #78369

Marc's Avatar Marc

😎

Txs a LOT Peter !
I'll test that tomorrow 😉

(you see, you now have an extra example to put on www.regularlabs.com/extensions/rereplacer/examples 😁

9 months 1 week ago #78409

Marc's Avatar Marc

Hi Peter,
We're almost there :
* I have created the ReReplacer
* for the moment, I have made no filter so it should trigger on all Pages
* and indeed, it triggers on a normal Page, but when on the Page where the field is called via Articles Anywhere (a table with all conferences with speakers), the replacement is *not* triggered

Any idea ?
Txs

9 months 1 week ago #78410

Peter van Westen's Avatar Peter van Westen Admin

It is probably due to the system plugin ordering. Try changing the ordering of the plugins in question.
See: www.regularlabs.com/blog/242-plugin-order-is-important

9 months 1 week ago #78411

Marc's Avatar Marc

Yep, it is the first thing I thought of.

I had inverted ReReplacer with Articles Anywhere for example, but then my article would show my rough code for articles anywhere : {articles ...}

Here is my order
screenpresso.com/=GY9be

Do you see anything suspect ?
Or are there other plugins/orders at work than System Plugins ?

txs

9 months 1 week ago #78412

Peter van Westen's Avatar Peter van Westen Admin

Are you.using ReReplacer you output Articles Anywhere code which outputs stuff you want to change with ReReplacer again?

If so, set the first replacement to Search Area "Articles". And order ReReplacer after Articles Anywhere.

9 months 1 week ago #78413

Marc's Avatar Marc

As soon as I order ReReplacer After Articles Anywhere, I get the following :
screenpresso.com/=4NhHf

as you see, the Article Anywhere code is displayed without being "processed".
In that code, I have [intervenants] (meaning [speakers] in French).

But when ReReplacer is before Articles Anywhere, then the ReReplacer which should be applied to Article Fields does not trigger (nothing is stripped from the Custom HTML of the Articles Field)

9 months 1 week ago #78415

Peter van Westen's Avatar Peter van Westen Admin

So are you using ReReplacer to output (something that outputs) Articles Anywhere code?

9 months 1 week ago #78416

Marc's Avatar Marc

Issue solved !

Actually, I was using ReReplacer to replace

{conf2018}
by
<table class="table table-striped">
	<thead>
		<tr>
			<th style="width: 25%;">Intervenant(s)</th>
			<th style="width: 55%;">Conférence</th>
			<th style="width: 7%;">Vidéo</th>
			<th style="width: 7%;">SlideShare</th>
			<th style="width: 7%;">Fichier PDF</th>
		</tr>
	</thead>
	<tbody>{articles category="18" ordering="title ASC"}
		<tr>
			<td>[intervenants]</td>
			<td>[link][title][/link]</td>
			<td>{if youtube}<a href="[youtube output=" target="_blank" rel="noopener"><span class="btn btn-sm btn-primary"><i class="fa fa-eye"></i> Voir</span></a>{/if} {if vimeo}<a href="[vimeo output=" target="_blank" rel="noopener"><span class="btn btn-sm btn-primary"><i class="fa fa-eye"></i> Voir</span></a>{/if}</td>
			<td>{if slideshare}<a href="[slideshare output=" target="_blank" rel="noopener"><span class="btn btn-sm btn-primary"><i class="fa fa-slideshare"></i> Ouvrir</span></a>{/if}</td>
			<td>{if pdf}[pdf]{/if}</td>
		</tr>
		{/articles}</tbody>
</table>

and another ReReplacer would do what you mentionned above.
But then the latter does not trigger...

If I put my whole table in my article itself, then the trick to have multiple Layouts for Article Fields does work 🙂

So obviously, the fact there are two ReReplacer prevents them to process correctly.

Temporarily, I have put my table back in the article, but would you see a way to make the *two* ReReplacer work together ?

9 months 1 week ago #78418

Peter van Westen's Avatar Peter van Westen Admin

Yes, if {conf2018} is only placed in articles (or Custom HTML modules), then set the Search Area of that replacement to Articles.
And Articles Anywhere should be ordered after ReReplacer.

This way ReReplacer does that replacement. Then Articles Anywhere sees the code and does it's thing.
Then at a later stage in the rendering process (where all other 'Search Area' replacements are done) ReReplacer can do it's thing again.
And finally Articles Anywhere gets another go to see if there are any {article} tags to convert.

9 months 1 week ago #78419

Marc's Avatar Marc

Excellent !

Indeed my order of plugins was correct from the start.
But by limiting the Search Area to Articles (instead of Body) it does now work.

Gosh, I was there at the RegularLabs in Antwerp, but I must have missed something subtile there in the order of processing when there are different Search Areas 🙂

Txs a LOT, it is now perfect !
(I had given a try with {snippet }, but the side-effect was that the Editor there would break my code (because the {articles } tag is inside the <table> and the Editor "corrects" the html when toggling...)

9 months 1 week ago #78424

Peter van Westen's Avatar Peter van Westen Admin

🙂

7 months 5 days ago #79770

Andy Badwool's Avatar Andy Badwool Moderator

Late comer... Just reading this and I thought this could be done with CSS...

Custom HTML layout:

<div class="layout-1">[tags for layout number 1]</div>
<div class="layout-2">[tags for layout number 2]</div>

On pages where you want layout 1, give that page a class "layout-1" and then give that class this:
.layout-2 {display: none;}

On pages where you want layout 2, give that page a class "layout-2" and then give that class this:
.layout-1 {display: none;}

Not super clean but probably easier/faster...