Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Jacques Corby-Tuech Posted April 30, 2017 Posted April 30, 2017 Hi, Is it possible to get other fields than the title from a Database Relationship field in Pages. For example, I would like to return the related field thumbnail image in the listings recordrow template. Thanks!
opentype Posted April 30, 2017 Posted April 30, 2017 It’s easy to do in the theme template “basicRelationship”. But that will be used for any database relationship field.
Jacques Corby-Tuech Posted April 30, 2017 Author Posted April 30, 2017 Hmm, yeah I only need it to apply to certain fields in certain templates.
bfarber Posted May 1, 2017 Posted May 1, 2017 In the basicRelationship template you can use HTML logic in order to show different things for different databases. {{if $item::$customDatabaseId == 4}} // Show item from db 4 ... yes you can access any fields including the record image field {{else}} // Everything else, i.e. what is in the template now {{endif}}
Jacques Corby-Tuech Posted May 1, 2017 Author Posted May 1, 2017 3 hours ago, bfarber said: In the basicRelationship template you can use HTML logic in order to show different things for different databases. {{if $item::$customDatabaseId == 4}} // Show item from db 4 ... yes you can access any fields including the record image field {{else}} // Everything else, i.e. what is in the template now {{endif}} That's a great tip, however I'd love to have more granular control, for example display Database 1 on database 2 one way and Database 1 on Database 3 in another way. I can sort of get around this with CSS and display:hide but that's not ideal at all.
opentype Posted May 1, 2017 Posted May 1, 2017 17 hours ago, Jacques Corby-Tuech said: That's a great tip, however I'd love to have more granular control, for example display Database 1 on database 2 one way and Database 1 on Database 3 in another way. The code for multiple databases would be … {{if $item::$customDatabaseId == 4}} // Show item from db 4 ... yes you can access any fields including the record image field {{elseif $item::$customDatabaseId == 5}} // Show item from db 5 {{else}} // Everything else, i.e. what is in the template now {{endif}} You can check for all sorts of things. That being said: I am also interested how to do this easily in a database template. Changing the theme template is easy enough, but if I would want to do that in a Pages template to be put on the Marketplace for example, the theme edit wouldn’t help me very much.
Jacques Corby-Tuech Posted May 1, 2017 Author Posted May 1, 2017 9 minutes ago, opentype said: The code for multiple databases would be … {{if $item::$customDatabaseId == 4}} // Show item from db 4 ... yes you can access any fields including the record image field {{elseif $item::$customDatabaseId == 5}} // Show item from db 5 {{else}} // Everything else, i.e. what is in the template now {{endif}} That being said: I am also interested how to do this easily in a database template. Changing the theme template is easy enough, but if I would want to do that in a Pages template to be put on the Marketplace for example, the theme edit wouldn’t help me very much. I think my point wasn't as clear as it could be. I want to be able to show items for a specific database, ie databaseID 1 in different ways depending on where it's being shown. For example a simple list of linked items on DB2, but a complex structure on DB3. In this case it shows items from DB1 in the same way, regardless of where they're being shown. This did however solve another problem I had regarding the correct formatting for getRecipocalItems()
TDBF Posted July 9, 2017 Posted July 9, 2017 On 01/05/2017 at 1:12 PM, bfarber said: In the basicRelationship template you can use HTML logic in order to show different things for different databases. {{if $item::$customDatabaseId == 4}} // Show item from db 4 ... yes you can access any fields including the record image field {{else}} // Everything else, i.e. what is in the template now {{endif}} I might be wrong, as I am still trying to figure this out, but this really seems the wrong way to go about this. What you are suggestion as a 'workaround' for this would soon become a spaghetti mess of long winded if's and else's. This could have been implemented a lot easier and a lot more developer friendly. Why not add another method to the class that would allow developers the ability to access information from the related class: {{$related = $record->getRelatedbyKey('key');}} {$related->customFieldDisplayByKey('related_key1')|raw} {$related->field_10|raw} <a href="{$related->url()}">{$related->customFieldDisplayByKey('key2')|raw}</a> Or {$record->getRelatedbyKey('key')->field_10|raw} This seems a lot more logical and gives the freedom working with template code and html, without the secondary need to edit another template (which would most likely grow in a uncontrollable monster when adding many databases. nb: the methods above are for example purposes (before I get told they do not exist).
Recommended Posts
Archived
This topic is now archived and is closed to further replies.