Search
Other Articles Anywhere questions
Forum

I can't use [category-id] or [category-alias] into a PHP variable

Fabio Zignale's Avatar Fabio Zignale
Hi everybody.

I am not able to use data from Article Anywhere in a PHP IF or SWITCH.

The following is PHP code inside {articles}{/articles}.

Example:
$category = '[category-id]';

if ($category == 10) {
DO SOMETHING
} else {
DO SOMETHING OTHER
}

i tried to change the $category variable cast turning it into numbers but nothing,

or with a switch with CATEGORY-ALIAS data:
$category = '[category-alias]';

switch ($category) {
case 'category-1':
	DO SOMETHING
	break;
case 'category-2':
	DO SOMETHING
	break;
}

i can see the changing values for every article into {articles} when echo the variable, it seems a string, but i can't use it and i can't match the category-alias into my php switch.

I've lost one day of trials: how i can i get a "clean" value from article anywhere to put into my php code?
Andrea Malalana's Avatar Andrea Malalana
Unfotunately, you can't.

PHP code will be interpreted before the {articles} tags.

The {articles} tags are replaced after the PHP code has already run.

So unfortunately you cannot store Articles Anywhere values as PHP variables.
Fabio Zignale's Avatar Fabio Zignale
Clear.
Thank you Andrea.
Peter van Westen's Avatar Peter van Westen ADMIN
You could potentially do this if you use Sourcerer to place the PHP code.
But you would have to convert the PHP code to HTML entities.

Are you trying to do all this in a PHP file?
Where do you need the result? Inside an article or something?
Please post a rating at the Joomla! Extensions Directory
Fabio Zignale's Avatar Fabio Zignale
Hi Peter, i love Regular Labs extensions!

So, in this specific case i'm using it on a module that allows HTML, PHP and Javascript codes (Flexi Custom Code).

If i remember correctly i used something similar code somewhere else (maybe directly in a php file?), but in this case there's no possibility to make it working in that way (inside a module that makes an article header), i lost over a day in trials.

Confidential information:
(hidden)


I solved with Article Anywhere conditional content (i needed to assign to a DIV some classes in function of CATEGORY-ID and language --get by php from Joomla $language = JFactory::getLanguage(); $language = $lingua->getLocale()[4];--).

Article Anywhere is a GREAT extension, i can mix HTML, PHP and ARTICLE ANYWHERE tags to make Joomla incredibly powerful!
I mixed them with satisfaction inside modules and articles layout overrides making complex websites.

Thank you for your extensions!
Peter van Westen's Avatar Peter van Westen ADMIN
Awesome!
PS: You might want to look into Sourcerer. You can also use that inside modules…
regularlabs.com/sourcerer
Please post a rating at the Joomla! Extensions Directory
Fabio Zignale's Avatar Fabio Zignale
I will try it.
Thank you!
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription