MODX Community

Output modifier on placeholder string . can't make it

Hi,

Despite the long experience I could have with Modx, I’m totally puzzled with output modifiers in Revo 2.6.5. (well it’s a fact I’m not used to play with modifiers)…

I need to change the value of a placeholder. To turn a string into another.
[[+thisParent:is=HPLC:then=hplc:else:is=GC:then=gc]]

this does not output anything. it is just empty.

the +thisParent is actually correctly populated by a GetParents snippet.
In this exemple the string change corresponds to a case transformation but it could be different in the future.

What’s wrong ??
thank you

first try it simple, like that:

[[+thisParent:is=`HPLC`:then=`hplc`:else=`gc`]]

does this work?
Did you maybe call your snippet uncached?

Thank for your help

this returns now something: ‘gc’
but the placeholder is actually ‘HPLC’ …so it should return ‘hplc’

I tested too when the placeholder is GC and it returns gc too…

seems the placeholder isn’t set at the time, when it is parsed.
As I allready asked, did you maybe call your snippet uncached, but the placeholder cached?

hmm. yes
here the test code (some part are “-”
[[!GetParents]]

<!-- [[+thisParent]] - [[-thisParent:is=`"HPLC"`:then=`"hplc"`:else:is=`"GC"`:then=`"gc"`]] ** [[+thisParent:is=`HPLC`:then=`hplc`:else=`gc`]] the real usage is after this..i'll show it once this woks.. the rendered code is: HPLC - ** gc

calling uncached too the PL make this working
[[!+thisParent:is=HPLC:then=hplc:else=gc]]

But this won’t work better:
[[!+thisParent:is=HPLC:then=hplc:else:is=GC:then=gc]]

The real case would be to test among 3 values - and potentially more.
So something wrong when chaining then/else ??

maybe better to create a custom snippet or use something like
https://modx.com/extras/package/switch
in this case

oh… well ok but so disapointed …each time I 'm stuck, it’s often a do a custom snippet…well not lucky…

As I thought the combination of scall into into call does not work
[[!ShowSolr4?&rows=500 &prodt=[[+thisParent]] &fab=[[*pagetitle]]
&ff=&facet.field=marque_[[!switch? &get=[[!+thisParent]] &c1=HPLC &do1=hplc &c2=GC &do2=gc]] &facet.field=phase_hplc &facet.field=dim_long &facet.field=dim_diam &facet.field=dim_part &facet.field=dim_pore
&tplFacets=tplFacets2]]

I need to pass some value to arameter for a custom snippet that will get some data into our SOlR server.
one of the paramter (a facet) is the thisParent modifier.
including switch (that works outside) just crash the site…
Fatal error : Cannot redeclare traduction() (previously declared in /var/www/vhosts/xxxxxx.fr/httpdocs/core/cache/includes/elements/modsnippet/146.include.cache.php:22) in /var/www/vhosts/xxxxx.fr/httpdocs/core/cache/includes/elements/modsnippet/146.include.cache.php on line 56

So the only way seems to use a custom snippet to determine the ‘marque_xxx’ needed value…
:roll_eyes: :confused:

I don’t think, the crash has todo with the switch-snippet, but with the ShowSolr4 - snippet

And you have the placeholder thisParend called cached, again

this ShowSolr snippet is working find since 2 years.
I can try to put all placeholders with a ‘!’ but the issue looks like it’s coming from string manipulation inside it doing some language translation.
adding the !switch snippet inside the Showsolr4 call seems to brake this without any logic from my point of view.
the line 56 mentioned into the error is the closing } of this code (extract):

$aTrad = [ 
		"product_type" => "Type Produit",
		"fabricant_facet" => "Fabricant",
		"marque_hplc" => "Marque HPLC",
		"phase_gc" => "Marque & phase GC",
		"phase_hplc" => "Phase HPLC",
		"marque_gc" => "Marque GC",
		"dim_long" => "Longueur",
		"dim_diam" => "Diamètre",
		"dim_part" => "Taille particule",
		"dim_pore" => "Taille de pore",
		"missing" => "Non renseignés" 
];

if ($current_CKey == 'en') {
	$aTrad = [ 
			"product_type" => "Product type",
			"fabricant_facet" => "Manufacturer",
			"marque_hplc" => "HPLC brand",
			"phase_gc" => "GC brand & phase",
			"phase_hplc" => "HPLC phase",
			"marque_gc" => "GC brand",
			"dim_long" => "Length",
			"dim_diam" => "Diameter",
			"dim_part" => "Particle size",
			"dim_pore" => "Pore size",
			"missing" => "Not specified" 
	];
}

return isset ( $aTrad [$texte] ) ? htmlentities ( $aTrad [$texte] ) : $texte; // français par défaut

}

the error might come from this unprocessed placeholder, if called cached

&prodt=[[+thisParent]]

I think, you could also call this snippet, which sets the placeholder, cached and then also the placeholders cached. I see no need to call the snippet uncached, if all what it does, is getting values from parent.

oh no it does a lot of things.
This a specific custom requester to a SolR server.
Solr is a search engine we implemented specifically to provides efficient filtering among dozen of thousands of articles codes.

I’m talking about the [[!GetParents]] snippet