10 years ago
Topic

Hi

We have a fieldX on an image field. On the content view we just want to display the FIRST image of the collection. With the image typo plugin a click on it will display the images with the arrow navigation. BUT the content view still displays ALL the images of the collection.

Is there a way to ONLY display the first image of the collection please ?

thanks

cyril

Get a Book for SEBLOD
572 Posts
_jrmo
10 years ago
0
Level 1

Hi Cyril,

The only way I know how to do this is by using a template override on your Content View and accessing the first image using the following php:

echo $cck->get( 'field_x_field_name' )->value[0]->value

You could *try* using this as the HTML field typo on the Field X to see if it works, but I'm not sure it will. 

<img src="/$cck->get( 'field_x_field_name' )->value[0]->value;" />

Otherwise use the template override. If you want to get the Thumb1 (or Thumb2 or Thumb3) you can use:

echo $cck->get( 'field_x_field_name' )->value[0]->Thumb1

_jrmo

10 years ago
3
Level 1

Hi James

The $cck->get() method doesn't work in a HTML typo so the override will be the solution!

thanks

cyril

4229 Posts
Kadministrator
10 years ago
2
Level 2

$cck->get('fieldname') works fine in html typo.

10 years ago
1
Level 3

Hi Klas

Actually it makes the page crash as soon as I put such a typo on a fieldx image.

In the element view of a list I have a bo_pro_plusieurs_img fieldX and I put a HTML typo plugin on this fieldX:

I tried

<img src="/$cck->get( 'bo_pro_plusieurs_img' )->value[0]->value;" />

and

$cck->get( 'bo_pro_plusieurs_img' );

But I got:

(! ) Fatal error: Cannot access empty property in C:\dev\projects\oti2014\workspace\plugins\cck_field_typo\html\html.php on line 134
Call Stack
# Time Memory Function Location
1 0.0006 684424 {main}( ) ..\index.php:0
2 0.0551 5359584 JApplicationCms->execute( ) ..\index.php:40
3 0.0551 5359584 JApplicationSite->doExecute( ) ..\cms.php:251
4 0.1323 12263120 JApplicationSite->dispatch( ) ..\site.php:237
5 0.1383 12285184 JComponentHelper::renderComponent( ) ..\site.php:191
6 0.1407 12292792 JComponentHelper::executeComponent( ) ..\helper.php:332
7 0.1410 12344720 require_once( 'C:\dev\projects\oti2014\workspace\components\com_cck\cck.php' ) ..\helper.php:352
8 0.1524 13511424 JControllerLegacy->execute( ) ..\cck.php:21
9 0.1524 13511504 CCKController->search( ) ..\legacy.php:730
10 0.1524 13511552 JControllerLegacy->display( ) ..\controller.php:522
11 0.1588 14325152 CCKViewList->display( ) ..\legacy.php:693
12 0.1638 14928184 CCKViewList->prepareDisplay( ) ..\view.html.php:31
13 0.1670 15298032 include( 'C:\dev\projects\oti2014\workspace\libraries\cck\base\list\list_inc.php' ) ..\view.html.php:94
14 0.2967 28751088 CCK_List::render( ) ..\list_inc.php:365
15 0.2972 28808688 include( 'C:\dev\projects\oti2014\workspace\libraries\cck\base\list\list_inc_list.php' ) ..\list.php:223
16 0.3016 29002616 include( 'C:\dev\projects\oti2014\workspace\libraries\cck\base\list\list_inc_list_items.php' ) ..\list_inc_list.php:85
17 0.3449 31096848 JCck::callFunc_Array( ) ..\list_inc_list_items.php:154
18 0.3449 31097024 call_user_func_array ( ) ..\cck.php:31
19 0.3449 31097600 plgCCK_Field_TypoHtml::onCCK_Field_TypoBeforeRenderContent( ) ..\cck.php:31

572 Posts
_jrmo
10 years ago
0
Level 4

I think Klas misread the post ;)

Klas is correct that the $cck->get() method works in an HTML typo, but it does NOT work on a Field_x in order to retrieve individual parts of the array.

The solution here is to use a template override, and use:

echo $cck->get( 'field_x_field_name' )->value[0]

(you don't need the second -> value).

Thanks,

James

4229 Posts
Kadministrator
10 years ago
1
Level 1

Hi,

for field_x you need to use this:

$cck->getValue('fieldname,0');

where number in field name is its index. Seblod is full of hidden tricks :)

10 years ago
0
Level 2

Hi again

Thanks a lot, it works!

I think you should write a blog where you summarize all the possible expressions we can write in a HTML typo please

thanks

cyril

9 years ago
1
Level 1

Hi again

the $cck->getValue('fieldname,0'); method works but how can we force it to display the thumbnail n on it ?

Generally, for an images gallery we need to display the first image of the gallery but not the real big original image. Since the thumbnail does exist on each item for the fieldX, is there a special synatx to force to display the thumbnail [n] on it ?


thanks


cyril

9 years ago
0
Level 2

Hi

Nobody can answer this last question please ?

thanks

cyril

9 years ago
2
Level 1

Hello Cyril,

what I would advise it's not the same way.

I would put the typo image on my fieldX, so like that you can define, which thumb to display, and if yes or not you want the modal on the thumb.

Then, in a field beforerender, I would explode the typo property of my fieldx with the string '</a>' (if link modal) or '/>' if only thumb without link to modal.

with that you have a array of thumbs, so you just have to set again the typo property of the fieldx with only the desired image.


Something like : 

$imgs = explode( '</a>', $fields['image_fieldx_fx']->typo );
$fields['image_fieldx_fx']->typo = $test[0].'</a>';<br>


or without link to modal : 

$imgs = explode( '/>', $fields['image_fieldx_fx']->typo );
$fields['image_fieldx_fx']->typo = $test[0].'/>';<br>


Best regards.

Lionel

9 years ago
0
Level 2

Hi Lionel

Thanks for the idea but this will only display a thumb of the selected image and I won't be able to browse among all the images of the fieldX

What I was looking for was:

1- only show the thumb of the first image of the fieldX (your solution  perfectly answers this issue)

2- when we click on the thumb we can navigate among all the images of the fieldX (your solution discard all the remaining images)

cyril

1 Post
zed
9 years ago
0
Level 2

Hi Lionel! I'm not familiar with php, but can understand by examples. In the post above described example:

$imgs = explode( '</a>', $fields['image_fieldx_fx']->typo );
$fields['image_fieldx_fx']->typo = $test[0].'</a>';<br>

Tell me what variable to test and apply this code? As I understand it in the html code of the field it won't work.

9 years ago
1
Level 1

Hi Cyril,

so instead of not displayed other thumbs, simply add them the style="display:none;" with a str_replace();

$imgs = explode( '</a>', $fields['image_fieldx_fx']->typo );
$html = '';
foreach ( $imgs as $key => $img ) {
    if ( $t ) {
        $replace = ( $key )? '<a style="display:none"' : '<a';
        $html .= str_replace( '<a', $replace, $img ).'</a>';        
    }
}
$fields['image_fieldx_fx']->typo = $html;


Best regards.

Lionel

9 years ago
0
Level 2

Thanks Lionel

that's perfect !

cyril

Get a VIP membership