Jump to content

How to acces to private field from $item member


Go to solution Solved by Poseidon2,

Recommended Posts

Posted

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>
                        {{endif}}
                        {{$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>
                                {{endif}}
                                
                                {{if $counts = $item->objectDataCount}}
                                    <li><i class='fa fa-comment'></i> {$counts['words']}</li>
                                {{endif}}
                            </ul>
                        {{endif}}
                    </div>

 

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

 

Posted
$item->object()->customFieldDisplayByKey('my_key', 'display')|raw

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

Posted

Mhhh tried that but it did not worked 😞

But it is true that we already promote other thing than Custome entry.

Is there any way of checking if the specific field is existing ?

Posted
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 ?

  • Solution
Posted

Found !

 

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

 

I have exaclty what I want without error 🙂

  • Recently Browsing   0 members

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