get a variable into a layout Topic is solved

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
erick-b
Joomla! Explorer
Joomla! Explorer
Posts: 297
Joined: Tue Feb 17, 2015 10:25 am

get a variable into a layout

Post by erick-b » Sat Jul 09, 2022 7:27 am

Hi !

Joomla 4.x

in my template /html/com_content/category/default_articles i am doing a loop to get the image_fulltext

Code: Select all

//default_articles.php

[b]$r[/b] = 0;
foreach ($articles_ as $article) {
[b]$r++;[/b]
echo LayoutHelper::render('joomla.content.full_image', $article, [b]$r [/b]);
….
}
but i want to get my variable $r in the layout full_image.php

Code: Select all

//full_image.php

$params = $displayData->params;
$images = json_decode($displayData->images);

$myvar = [b]$r[/b] ?
how do i get $r value ?


thanks

erick-b
Joomla! Explorer
Joomla! Explorer
Posts: 297
Joined: Tue Feb 17, 2015 10:25 am

Re: get a variable into a layout

Post by erick-b » Sat Jul 09, 2022 11:50 am

It works
Problem solved

MarkRS
Joomla! Explorer
Joomla! Explorer
Posts: 329
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: get a variable into a layout

Post by MarkRS » Sat Jul 09, 2022 1:47 pm

It would be nice to post the solution so other people might benefit too :)
It's a community, the more we all contribute, the better it will be.

erick-b
Joomla! Explorer
Joomla! Explorer
Posts: 297
Joined: Tue Feb 17, 2015 10:25 am

Re: get a variable into a layout

Post by erick-b » Sat Jul 09, 2022 1:51 pm

instead of

Code: Select all

echo LayoutHelper::render('joomla.content.full_image', $article, $r );
we need an array as there is only one attribute possible

Code: Select all

		 $params = [
			'article' => $article,
			'load' => $r
		];

echo LayoutHelper::render('joomla.content.full_image', $params);
and to get it

Code: Select all

$images  = json_decode($displayData['article']->images);
$load =  $displayData['load'];


Locked

Return to “Joomla! 4.x Coding”