[Solved] Calling specific fields in template

More
9 years 7 months ago #49895 by agata
Hi,
I'm using the following code to load the first image of a slideshow (image field with multiple values) in the item.php

<img src="<?php echo $this->fields->{'display_large_src'} ?>" alt="<?php echo $item->title; ?>" />

It works a treat but when I use it in category_items.php (with very minor changes) it doesn't work

<img data-original="<?php echo $this->fields->{'display_medium_src'} ?>" alt="<?php echo $item->title; ?>" />

I added the field to a renderonly position. Unfortunately I'm not a PHP programmer and would appreciate suggestions for what I'm doing wrong.
Thanks,
Agata

Please Log in or Create an account to join the conversation.

More
9 years 7 months ago #49896 by ggppdk
Hello

there is no:
$this->fields


in category view, remember you have many items and not only one item

you should use INSIDE the item loop:

$item->fields->{'display_medium_src'}


where $item is the item variable created by the loop displaying the items


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
9 years 7 months ago #49898 by agata
Code:
<?php foreach ($item) : ?> <img src="<?php echo $item->fields['field_slideshow']->{'display_medium_src'} ?>" alt="<?php echo $item->title; ?>" /> <?php endforeach; ?>
am I in the ballpark?

Please Log in or Create an account to join the conversation.

More
9 years 7 months ago #49900 by ggppdk
Hello

there must be a loop there already !! don't place a new loop inside existing loop


it should be like this
Code:
<?php foreach ($this->items as $item) : ?> ... <img src="<?php echo $item->fields['field_slideshow']->{'display_medium_src'} ?>" alt="<?php echo $item->title; ?>" /> ... <?php endforeach; ?>



NOTE this or similar should exist already:
Code:
<?php foreach ($this->items as $item) : ?> ... <?php endforeach; ?>


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
9 years 7 months ago #49901 by agata
Oh dear, I was editing the wrong file (my brain isn't working too well 7.5 hours into an 8 hour day ;) ), thanks a lot, it works!

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.280 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline