Jump to content

Add custom field to database feed block


m3rk0rd

Recommended Posts

Posted

Can someone please tell me how to add a custom database field to a feed block? I have a home page with a block showing records from my "Articles" database, which includes a field named "teaser".

I remember this was pretty easy with IP. Content, but with Pages I can't figure it out. Here is what I've tried so far:

I created a new block using Pages > Page Management > Blocks > Create New Block. In the Create New Block dialog I selected Type: Plugin and I tried both "Record Feed" and "Feed from Articles" for the Plugin Type. Then under the Content tab I selected Template: "Default template" and "Use as a base for a custom template".

That get's me the following code. I'm placing my block in one column of a 3-column layout, so it uses the first bit of code ($orienation == 'vertical'). I see the foreach bit, so I assume I can access record fields using something starting with $record, but for the life of me I can't figure out what! For my "teaser" field I tried $record->teaser, $record->field_141, $record['teaser'], $record->customFieldDisplayByKey('teaser'). None of these seem to work in a block template, I assume they work only in page templates.

So if anyone could help I'd really appreciate it.

{{if !empty( $records ) }}
	<h3 class='ipsWidget_title ipsType_reset'>{$title}</h3>
	{{if $orientation == 'vertical'}}
		<div class='ipsPad_half ipsWidget_inner'>
			<ul class='ipsDataList ipsDataList_reducedSpacing ipsContained_container'>
				{{foreach $records as $record}}
					<li class='ipsDataItem'>
						<div class='ipsDataItem_icon ipsPos_top'>
							{template="userPhoto" group="global" app="core" params="$record->author(), 'tiny'"}
						</div>
						<div class='ipsDataItem_main cWidgetComments'>
							<div class="ipsCommentCount ipsPos_right {{if ( $record->record_comments ) === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="num_replies" pluralize="$record->record_comments"}'>{expression="$record->record_comments"}</div>
							<div class='ipsType_break ipsContained'>
								<a href="{$record->url()->setQueryString( 'do', 'getLastComment' )}" title='{lang="view_this_cmsrecord" sprintf="\IPS\Member::loggedIn()->language()->addToStack( 'content_db_lang_sl_' . $record::$customDatabaseId, FALSE ), $record->_title"}' class='ipsDataItem_title'>{$record->_title}</a>
							</div>
							<p class='ipsType_reset ipsType_medium ipsType_blendLinks'>
								<span>{lang="byline_nodate" htmlsprintf="$record->author()->link()"}</span><br>
								<span class="ipsType_light">{datetime="$record->mapped('date')"}</span>
							</p>
						</div>
					</li>
				{{endforeach}}
			</ul>
		</div>
	{{else}}
		<div class='ipsWidget_inner'>
			<ul class='ipsDataList ipsContained_container'>
				{template="recordRow" group="listing" location="database" app="cms" themeClass="IPS\cms\Theme" params="null, null, $records"}
			</ul>
		</div>
	{{endif}}
{{endif}}

BTW, I have searched every way I know how on these forums for an answer, and gone through the Help Guides several time, with no luck.

Posted

With the field key:

{$record->customFieldDisplayByKey('your_field_key', 'listing')|raw}
{$record->customFieldDisplayByKey('your_field_key', 'display')|raw}

With the field ID:

{$record->field_XX}

 

Keep in mind that blocks are cached when not IN_DEV, so when playing with that, it might be it works but you don’t see the result instantly. 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...