This topic is locked

Using Snippets inside list records?

12/31/2010 6:38:06 AM
PHPRunner General questions
B
belzant author

Hi,
I'm trying to author a snippet that needs to receive input from each record from a List page. The problem I'm having, is that only key data from the master record is passed to the snippet (via $strWhereClause), rather than the desired key-data for the list-entry records.
I'm competent at authoring SQL strings to target specific tables, but I don't know how to manage the key data necessary to target the List entry records.
How can I pass the key data from the html context (eg. From inside a {BEGIN grid_record} {$event record_snippet} {END grid_record} block), into the record_snippet itself?
Grateful for any response.

Sergey Kornilov admin 1/1/2011

Snippets don't have access to records on the List page. I suggest setting 'View as' type of one of fields to 'Custom' and placing your code there.

B
belzant author 1/1/2011



Snippets don't have access to records on the List page. I suggest setting 'View as' type of one of fields to 'Custom' and placing your code there.


Thanks for the response Sergey. I had already embarked on a Custom event script via "function BeforeProcessRowList(&$data)", as an attempt to achieve my goal. From reading the help text, I understand that the $data parm should contain a complete image of my List record, so I should be able to reference fields as $data["<field name>"] within the custom code; I think this is working but I'm not certain yet; Note the list record is a view & not a table (Does this matter?).
So my code attempts to prepare a dynamic uri which is dependent on the rowlist $data, therefore I'm assigning my output custom-code field as $tgturi & expecting to be able to reference this variable from within the {BEGIN grid_record}..<A href={$tgturi}><image_tag></a>..{END grid_record}.
This produces an unexpected result however (which appears to relate to unexpected data coming from the $data[] reference in the custom code. 3 questions -

  1. Is the approach described above close to what you meant in your response?
  2. Is the selected function BeforeProcessRowList function a good event choice for the objective?
  3. Please explain why the $tgturi might contain unexpected content from the $data[] reference? Note that the static elements of the $tgturi variable seem to be returning correctly to the list page html. If you need more specific info (eg. custom code) to respond further, please advise.
    Regards,

Sergey Kornilov admin 1/1/2011

Your approach won't work. You still need to use 'View as' type 'Custom' where you have access to all record fields via $data['FieldName'].

B
belzant author 1/2/2011



Your approach won't work. You still need to use 'View as' type 'Custom' where you have access to all record fields via $data['FieldName'].


Sorry Sergey - I understand your direction now & had made the attempt, but I encountered another constraint where the custom code (as selected from the field 'View As' panel), doesn't seem to allow reference to other fields from my source (list) view, & these are required as dependencies on one of the conditional uri's.
I've now achieved a satisfactory result by embedding a conditionally derived field on mysql view which allows reference to other fields in a 3-table join. Statement used was 'SELECT .. IF(condition, true-result, false-result) WHERE ..'
Thanks for your time & trouble to respond. I would still like to understand why my earlier approach wouldn't work.

Sergey Kornilov admin 1/2/2011

Your previous approach won't work because the only way to access record fields is to use 'View as' Custom. All other methods like code snippets or custom template variables don't have access to record data.