Hello Here s a quick problem, i am under Joomla trying to get the value of a variable in a plugin, inside a template. It looks more or less like this <?php $extrafieldsid[$itemid->id] = $itemid->value; } $variable = $extrafieldsid[11]; $plug1 ='{myplugin value1=\"<?php echo $variable;?>\" value2=\"bart\" value3=\"Maggie\" value4=\"popup\" value5=\"alf\" value6=\"400\" /}'; echo JHTML::_('content.prepare',$plug1); ?> Code (markup): if i test the value of $variable before or after the plugin, it works, but when the plugin returns value1 .. it returns the php code First person coming up with the right way to insert variable in the plugin code gets 10 by paypal. Other values are returned correctly .
<?php $extrafieldsid[$itemid->id] = $itemid->value; } $variable = $extrafieldsid[11]; $plug1 ='{myplugin value1=\ "$variable \" value2=\ "bart \" value3=\ "Maggie \" value4=\ "popup \" value5=\ "alf \" value6=\ "400 \" /}'; echo JHTML::_('content.prepare',$plug1); ?>
please change it to $plug1 ='{myplugin value1=\ "'.$variable .'\" value3=\ "Maggie \" value4=\ "popup \" value5=\ "alf \" value6=\ "400 \" /}';
Hi. What about using a randomized string marker, so you can replace it solely just before calling your plugin, at which point you should already have $variable set properly? Also, are you setting $variable in some PHP script/page, and then trying to access it from another one in the web? If so, then you would probably need to pass the value of the $variable via GET or POST at the very least. _____________________________ _____________________________ <?php $extrafieldsid[$itemid->id] = $itemid->value; //} //<-- This curly bracket seems to be an error/typo, but if it's not, just uncomment it! $variable = $extrafieldsid[11]; //BEFORE CALLING YOUR PLUGIN (Action 1 of 3): //Create a random marker as to //where to insert the '$variable' value: /// $plug1_rand="DOLLARvariable".mt_rand(); //BEFORE CALLING YOUR PLUGIN (Action 2 of 3): //See how now we reference our randomized //string marker instead of '$variable' directly. //Now we can get the correct value just when //it is ready for use. // //Note also that now our double quotes are //used in a more readable way (escaping them isn't //necessary as this string is quoted by single quotes): /// $plug1 ='{myplugin value1="'.$plug1_rand.'" value2="bart" value3="Maggie" value4="popup" value5="alf" value6="400" /}'; //BEFORE CALLING YOUR PLUGIN (Action 3 of 3): //See how now we apply a string replacement //on the randomized string marker. //AT THIS POINT, '$variable' SHOULD BE SET; //OTHERWISE, THERE IS ANOTHER ADDITIONAL //ERROR SOMEWHERE ELSE: /// echo JHTML::_('content.prepare', str_replace($plug1_rand, $variable, $plug1)); ?> Code (markup):
Did you make sure to remove the apparently missing curly bracket at line 3, and that you aren't generating Error 500 at the server side, or the like? Did you make sure that $extrafieldsid[ 11 ] actually contains something that isn't a blank string, and that you didn't mean to use $extrafieldsid[ $itemid->id ] instead? Aren't you setting $variable in a PHP document and pretending to reuse it by navigating away to a completely different PHP document (in which case you should pass the variable via GET or POST at the very least, by something like $_GET["DOLLARvariable"])? Chances are that the code is working, and you have another problem in your actual PHP script, which isn't showing here. The raw code worked for me, because I don't have the actual plugin. It worked like the following so I know this is working in its raw form. You indeed have another problem, but this problem has been solved in its raw form: <?php //Create a random marker as to //where to insert the '$variable' value: /// $plug1_rand="DOLLARvariable".mt_rand(); $variable="Change plug1_rand for me"; $plug1 ='{myplugin value1="'.$plug1_rand.'"\n value2="bart"\n value3="Maggie"\n value4="popup"\n value5="alf"\n value6="400"\n /}'; echo "<pre>".str_replace($plug1_rand, $variable, $plug1)."</pre>"; ?> Code (markup):
schlogo, ive have given it it a bit of research and it appears you cannot use php in the joomla content plugin tags without a extra extension like Jumi, directphp and the likes. As all our methods we have posted so far really do work (in a php point of view, excluding joomla ), i believe this is your issue here.
@Basti, actually, i guess php can't be used in content loke articles, but here, we are in the template, it should not be
Please give an example of the value. Then try the following code. Now I use a static string marker for the value where $variable should be. With this, now you can place that exact string code in a separate PHP "template" if you need it, and include it from another PHP script. In any case, please provide us with more relevant code. We have already solved the problem according to the data you have given. At this point it has to be working unless there are errors you aren't showing us. <?php $extrafieldsid[$itemid->id] = $itemid->value; //} //<-- This curly bracket seems to be an error/typo, but if it's not, just uncomment it! $variable = $extrafieldsid[11]; //BEFORE CALLING YOUR PLUGIN (Action 1 of 3): //Create a constant string marker as to //where to insert the '$variable' value: /// $plug1_const="DOLLARvariable_112233445599"; //BEFORE CALLING YOUR PLUGIN (Action 2 of 3): //See how now we reference our constant //string marker instead of '$variable' directly. //Now we can get the correct value just when //it is ready for use. // //Note also that now our double quotes are //used in a more readable way (escaping them isn't //necessary as this string is quoted by single quotes): /// $plug1 ='{myplugin value1="DOLLARvariable_112233445599" value2="bart" value3="Maggie" value4="popup" value5="alf" value6="400" /}'; //BEFORE CALLING YOUR PLUGIN (Action 3 of 3): //See how now we apply a string replacement //on the constant string marker. //AT THIS POINT, '$variable' SHOULD BE SET; //OTHERWISE, THERE IS ANOTHER ADDITIONAL //ERROR SOMEWHERE ELSE: /// echo JHTML::_('content.prepare', str_replace("DOLLARvariable_112233445599", $variable, $plug1)); ?> Code (markup): Remember to make sure that all of the used variables are defined and useable in both scripts before echoing finally at the last shown line, if you are using more than one PHP script for this, remember to use the GET/POST suggestion if it applies, and then please report back.