Jump to content

Variables - Pages


Wayne B

Recommended Posts

Posted

Hi

If I want to create a custom block in Pages to display the latest record from a custom database I appreciate I can use the default widgets for latest records in pages however that always displays the author of the record entry and is not what I want - I want to create a custom one so I can control the layout and content. 

In my custom database I have three database fields for each entry

  • Month (Currently Set as Title)
  • Reason (Currently set as Content)
  • Member (Additional field which stores the member ID in the table)

How can I display these in a custom block? How do I call them and display the results to screen? Specifically the Member field is done by utilising the member fields option in the field type so it searches the directory when you start typing. When it saves to the database it stores the member ID and not the member display name. 

So I am thinking of wanting to display the result of the latest record only limiting what is fetched to display as follows;

Month: $value (Hyperlinked back to the entry in the custom database in pages) - Title Field
Reason: $value
Member: $Member Display Name - with tiny profile image

Hopefully I have explained the above well enough and I can write the html and css to accompany it but I am not sure how to pull the values from the custom database.

Posted

Have you checked out the default block template? You can built on that and just replace what’s in the foreach loop. 

Inside, it works like in the regular Pages templates. So you can just call something like:

{$record->_title}

Pretty straightforward. 

Posted

For the member field (or any of such additional fields), do it like in the Pages templates as well. I just tried it. I set up a member field and could use in the block template like this:

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

 

Posted

Hi @Ralf H. thank you for the guidance.

So in our custom database in pages the reason field is 'field_35'

Are you saying it's as straight forward as;

{$record->customFieldDisplayByKey('field_35', 'listing')|raw}
Posted

The call I showed you uses the “template key”, not the “field id”. I’m sure you can use both in blocks, but the calls and the options are different. Using the field key you can make the usual layout  adjustments in the field settings. If you call the field directly, you directly output the field content.

Posted

The call I showed you uses the “template key”, not the “field id”. I’m sure you can use both in blocks, but the calls and the options are different. Using the field key you can make the usual layout  adjustments in the field settings. If you call the field directly, you directly output the field content.

​Thanks @Ralf H. 

One last query - from the default template it outputs 

{template="userPhoto" group="global" app="core" params="$record->author(), 'tiny'"}

Is there any way to modify this to use that same member field rather than the author so it display the profile image of the member instead of the author?

Posted

Probably. If your member field has just one member ID in it, it might work if your replace $record->author() with $record->field_XX. 
Haven’t tried though. Just a guess. 

Posted

@Charles @Mark - could anyone from Invision advise if this is possible to change the author to the member selected in the member field within pages so what to replace this with;

{template="userPhoto" group="global" app="core" params="$record->author(), 'tiny'"}

As mentioned in the posts above?

Archived

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

  • Recently Browsing   0 members

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