Jump to content

How to acces to private field from $item member

Go to solution Solved by Poseidon2,

Recommended Posts

Hi all.


I'd loved to put some private fields in my Our Picks preview. I found the right place to do it :

<div class='cPromotedWidgetItem_contentInner'>
                        {{if $text = $item->getText('internal', true)}}
                              <div class="ipsType_richText ipsType_medium ipsSpacer_both ipsSpacer_half">Note : {$item->customFieldDisplayByKey('my_key', 'display')|raw}</div>
                            <div class="ipsType_richText ipsType_medium ipsSpacer_both ipsSpacer_half" data-ipsTruncate data-ipsTruncate-type='remove' data-ipsTruncate-size='4 lines'>{$text|raw}</div>
                        {{$reactionClass = $item->objectReactionClass;}}
                        {{if $reactionClass || $item->objectDataCount}}
                            <ul class='ipsList_inline ipsType_light ipsSpacer_bottom'>
                                {{if $reactionClass}}
                                <li>{template="reactionOverview" group="global" app="core" params="$reactionClass, FALSE"}</li>
                                {{if $counts = $item->objectDataCount}}
                                    <li><i class='fa fa-comment'></i> {$counts['words']}</li>


But I could not acces to my rivte field using {$item->customFieldDisplayByKey('my_key', 'display')|raw}

Can anyone explain me my mistake ??


Thanks in advance


Link to comment
Share on other sites

19 minutes ago, bfarber said:

But be careful as this would result in an error if you promote anything other than a custom Pages database record.

Ok I have exactly what you are saying : it is working for my records but noote for the otehr posts promoted from the forum.


Any clue to avid that ? Can I check if my object is a record ?

Link to comment
Share on other sites

  • Solution

Found !


{{if $item->object() instanceof \IPS\cms\Records}}         
        <div class="ipsType_richText ipsType_medium ipsSpacer_both">{$item->object()->customFieldDisplayByKey('1001bd_Note')|raw}</div>


I have exaclty what I want without error 🙂

Link to comment
Share on other sites

  • Recently Browsing   0 members

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