Placeholder in list view - coding advice needed

Jaanus

Super Moderator
Hi,

I'm trying to create something new again ;) this time for list view in element level. And I need help to understand something.

In list view, parseMessageForRowHolder() replaces {tablename___elementname} with data, isn't it?

OK, when I use such placeholder in element's custom link param then it's parsed. In models/element.php parseMessageForRowHolder() seems to do this work.

But now I'm trying to make element to show under its original data also some data from other element(s) without any need to create a new calc element (and new database field) for this.
I created 2 new params 'other_data' and 'other_always' (means that it shows other data even when there are no original data displayed).
And in element.php I added some lines (since about 4380) into function renderListData:

PHP:
		$other = $listModel->parseMessageForRowHolder($params->get('other_data')); 
		$always = $params->get('other_always');
		$final = $this->renderListDataFinal($data);
		if ($other != '' && $this->renderListDataFinal($data) != '')
		{
		$final .= '<br />';
		}
		if (($this->renderListDataFinal($data) == '' && $always == '1') || $this->renderListDataFinal($data) != '')
		{
		$final .= $other;
		}
		return $final; //originally: return $this->renderListDataFinal($data);

Unfortunately, no parsing happens. When I write in 'other_data' param such string as e.g 'Other {tablename___elementname}' then this code "works" only for the word "Other" that is shown where needed - without any data that should replace {tablename___elementname}.

What is wrong? Do I need some second argument? e.g $listModel->parseMessageForRowHolder($params->get('other_data'), $some_second_argument)?

Many thanks in advance :)
 
Yes, you need to pass the row data as the second arg. Actually, I'm surprised it doesn't blow up without it.

In renderListData(), that would be $rowData.

-- hugh
 
BTW, rather than modifying the main element model, you'd be better of tweaking an individual element, like 'field'. Or better yet, create your own element, like field_calc or whatever, which just extends the field element, and would probably just need the renderListData() method in it.

See CDD for an example of an element which extends another (databasejoin).

-- hugh
 
Yes, you need to pass the row data as the second arg. Actually, I'm surprised it doesn't blow up without it.

In renderListData(), that would be $rowData.

-- hugh

Thanks,
but unfortunately, no success :(

Tested also separately with field element. Something else should be the second arg?
 
you'd be better of tweaking an individual element

If not element model then rather this way. My goal is to make list view more compact

- i.e case when we have date field + time field and the time field is often empty

Of course if I could I'd create a special element named i.e. "listcell" that would never have any db field behind and would be used only in list view, working like group by layout.
 
Do you have a fork on github I can look at? It should work, adding $rowData, but I'd need to see your exact code.

-- hugh
 
OK. I'm about to head out for a gig (I can already feel my B3 calling ... "play me!"), so remind me tomorrow when you see me on Skyoe, and we'll take a look.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top