This site uses cookies and similar technologies.

If you don't change browser settings, you agree to it.

I understand
153 Posts
redback
5 years ago
12
Topic

Hello,

made some trials with the "Add Code Before Render" Plugin.

Approach: Show a value of a field.

echo $cck->getValue('field_name');

Effect: This order doesn't work.

???: What ist the right order?

Thanks for helping.

Get a Book for SEBLOD
4229 Posts
Kadministrator
5 years ago
3
Level 1

Hi,

to get fields value in beforeRender you cna use $fields['yourfeild']->value, but chaging this property has no effect, you need to change $fields['yourfeild']->form. Form property contains rendered html that will show on the form.

153 Posts
redback
5 years ago
2
Level 2

Hello Klas,

thanks for your quick answer. Is there an documentation over all the available variables in seblod?

4229 Posts
Kadministrator
5 years ago
1
Level 3

Hi,

unfortunately there is no such documentation yet, usually the quickest way is to look in the code of the plugin

153 Posts
redback
5 years ago
0
Level 4

Hello Klas,

thanks for you help.

1219 Posts
Bucklash
4 years ago
7
Level 1

Hi

I am trying to understand this post, can anyone assist with part of Klas's reply?

to get fields value in beforeRender you cna use $fields['yourfeild']->value, but chaging this property has no effect, you need to change $fields['yourfeild']->form. Form property contains rendered html that will show on the form.

So in beforeRender field, you can use:

$fields['my_field_name']->value.

-> "but changing this property has no effect"

This has me confused.

Is it implied changing the word "value" to "text", "html", "typo" has no difference, output is the same?

Also is it the case that 

$cck->getValue('my_field_name');

does nothing in this context (beforeRender)?

  

This is the first time I have noticed the use of the word 'form' (my ignorance shines brightly)

$fields['my_field_name']->form

  

 Any tips on when the word 'form' should be used?

Thanks 

Bucklash

153 Posts
redback
4 years ago
6
Level 2

Hi Bucklash,

here an tipp for you: Just check the array, than you know how to call the field. If you put these line at your code you can read out the array in the frontend.

print_r($fields) and die;

Best

Christian

1219 Posts
Bucklash
4 years ago
5
Level 3

Hi Redback

Any tips on 'how' I put it in my code.

If I put in the template file:

<?php print_r($fields) and die; ?>

the site explodes in to a million pieces and curses me forEVER!!

   

If I put

print_r($fields) and die;

in a beforeRender field and place it on my form, not a lot happens so I go and make a cup of coffee.

That's me pretty much out of ideas...

So maybe, I have to think laterally, ie Is $fields a variable that I should be replacing with something else? I don't think it is...

Thanks :)

Bucklash

153 Posts
redback
4 years ago
4
Level 4

Hello Bucklash,

you need to know php, otherwise its to difficult to explain. 

You put the code in your field. After that you should get a white page at the frontpage. Now you analyze your sourcecode on the frontpage and interpret the array output. After that you know how to call the field.

Best

1219 Posts
Bucklash
4 years ago
3
Level 5

Hi Redback

Thanks for your help.

I have indeed got the array showing. And damn there's a lot of info...

The reason I had no joy yesterday is because I was making a silly mistake. The menu item pointed to a content type I had created earlier with a slightly different name, so I didn't notice at first ie content_type_1 vs content_type_01. Lesson learned there!!

If cool with you, I will reply soon with a question to make sure I am on the right track. Nothing too heavy :)

Bucklash

1219 Posts
Bucklash
4 years ago
2
Level 6

Hi Sebloders

Any feedback to these questions would be greatly appreciated :)

Am I correct?

Usage

$fields: Use this in a field, like beforeRender, or in an SQL query

$cck: Use this in a template file, like in a position override or as a variation.


 

Syntax

Correct :)

$fields['cat_title']->id; 

$cck->getId('cat_title');

Incorrect :(

$fields->getId('cat_title');

$cck['cat_title']->id;

 

Bucklash 

4 years ago
1
Level 7

Hello All,

thank Bucklash for all your help on the forum.

You're right, there is two way to get values, depending on where you are.


In all plugin CCK field code (BeforeRender, BeforeStore, Afterstore,..) you have access only to 2 variables :

  • $fields   => the array of all fields in the view
  • $config  => the array of all configuration of the context

in general for all views, in the $config variable, you can find :

  • $config['pk']   => The ID in the article (#__content table)
  • $config['isNew']   => 1 for Add / 0 for Edit
  • ....

For "Storage Event", you have also access to the variable :

  • $config['storages']

in this variable, all datas configured will be stored or have been stored.


In template, you have access to the object "$cck" and can get properties of a field by the syntax :

  • $cck->getProperty('field_name');

where Property must be replaced by the Propery expected, like : Value, Link, Html, Thumbx, Text, ......


Now, when you want to debug, you also have the solution with the extension JDump, which is very easy to use.

You can add the tag "dump( $my_object, 'My Object' );" everywhere in your code and you will see Properties and Methods available on your object


Regards.

Lionel

1219 Posts
Bucklash
4 years ago
0
Level 8

Hi Sebloders

   

Thanks Lionel. 

JDump is indeed really cool.

I have seen you mention it a few times, but my brain can only take so much at a time...

Bucklash

Get a Book for SEBLOD