Other Snippets questions

Joomla4 snippets with parms , how to describe

Hans-Günter Heiserholt's Avatar Hans-Günter Heiserholt
Hey Peter,

I'm just migrating to J4.

In J3 I have some snippet entries like

{snippet MySnippet|parm1|parm2}
parm1,parm2,.... are substituted in MySnippet by the placeholders \1, \2, ... on the fly.

How can I get this feature running in J4?

I'v tested this
{snippet alias="MySnippet" parameter1="parm1" parameter2="parm2"}
I read that as a solution in a posting here.

In that case, I get a substitution result of only \1 \2.

What is wrong?
I'm missing a detailed docu of that feature, or is it rebuild in J4?.
Peter van Westen's Avatar Peter van Westen ADMIN
Please read the Joomla 4 documentation:

And mainly this:
Please post a rating at the Joomla! Extensions Directory
Hans-Günter Heiserholt's Avatar Hans-Günter Heiserholt
Hi Peter,

oh oh. A lot of stuff and a greate new jungle of parms! 😉

I got it to run for an example.

But now there are more questions. I have at least 91 ! J3 snippets with parms like "\1, \2, \3,\...".
Is there a way to automise the conversion process to a J4 snippet, or must it been manually done?

I have the following idea:

1) In the spippet itself the old \1,\2,\... placeholders must be changed to %parm-1%, %parm-2%, %parm-n%. This could be done with the help of DB-Replacer. is there a way to do it via regex?

2) in the syntax of the J3 {snippet alias-txt|text1|text2|text...} must change
to a J4 format as {snippet alias="alias-txt parm-1=text1" parm-2="text2" parm-n="textn"}

This should be very complex to do it automatically, or is there a regex doing it?

3) The next very complex thing is to individually save the parms for each snippet in the J4_snippets table in den DB.
Is there a way to generate a text file, witch content can be loaded into the DB via myPHPAdmin?

Oh oh, that all will cost a lot of livetime.
Peter van Westen's Avatar Peter van Westen ADMIN
You can use DB Replacer and Regular Expressions to replace the syntax.
But you will have to manually add the new parameters.

With the regex, you can't just make it replace any amount or params and have it name them with the dynamic number. So you would need to check what the amount of params are and then name the params how you wish.

For instance for 4 params:
{snippet ([^\|\}]*)\([^\|\}]*)([^\|\}]*)([^\|\}]*)([^\|\}]*)}
Replace with:
{snippet alias="\1" parm-1=\2" parm-2="\3" parm-3="\4" parm-4="\4"}
{snippet alias="\1" what=\2" ever="\3" you="\4" want="\4"}

And repeat that for any number of params you use.

You can of course also first replace any snippets by their alias that you want to give specific param names.

One of the great advantages of the param name approach is that you can do any of these, and they'll all work:
{snippet alias="contact" name="Peter" surname="van Westen"}
{snippet alias="contact" surname="van Westen" name="Peter"}
{snippet name="Peter" surname="van Westen" alias="contact"}
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