151 Posts
jimenaes
8 years ago
Topic

Hello

I'm not sure if what I want to do is possible or if it's the right way to do it. I have a content type with many fields and I need to display all of them in the content view but three of them inside a slider. So, I thought this could be done displaying all the fields inside the main body position (from the One template) and make the slider using the before render field writing the PHP code and put it in the top body position. The problem I have is that one of the three field is a groupX field and I need to make an array with the values of the field1 (file), field2 (image) and the groupx fields (could be from 0 to 20). I have been searching in the forum and in the tutorials and manuals but could not found how to get those fields values using the Before render field. I found examples to make a custom template but not to use the code pack and so far I understand the way to get the fields value is different in this case. 

Does anybody could give me a clue?

Thanks a lot

Get a VIP membership
8 years ago
1
Level 1

Hi jimenaes,
yes it's possible to do that.


by this way:
in the content wiew, add your 3 fields nedeed for the slideshow in the position "Clear" Not visible but available in the array of fields.
Add a Freetext (wysiwyg empty) in the position where you want to dispmlay your slideshow.
Add a beforerender field and make your code for the slideshow here.

The purpose is to create the html code of your slideshow and to put it in the property "Value" of the freetext field.

To make your code, you can get the value of the three fields by this way:

$data1 = $fields['field_name1']->value;

$data2 = $fields['field_name2']->value;

...



To access to a groupX value it's the same, but you will get the string of the custom storage, so you must execute a preg_match_all on this string to get all nedeed values of the groupX in an array

Something like:

$groupx = $fields['groupx_field_name']->value;
$pattern = '#::(.*?)\|(.*?)\|(.*?)::(.*?)::/(.*?)\|(.*?)\|(.*?)::#s';
preg_match_all( $pattern, $groupx, $matches );<br>

So in the $matches, you will get all data from the groupX in the array $matches.
You can adapt this pattern to your need.

Then, when the slideshow html is done, you just have to put it in the freetext :

$fields['freetext_field_name']->value = $slideshow_html;

In the beforender field you can also load all javascript nedeed (JFactory::getDocument()->addScript....)


Regards

Lionel

151 Posts
jimenaes
8 years ago
0
Level 2

Thanks a lot Lionel, I will try it.

Get a Book for SEBLOD