Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Dreadknux Posted August 30, 2023 Posted August 30, 2023 (edited) Hi all, quick question on this fancy little 'Topic Format' feature I've only just noticed in Pages' custom fields section (very VERY handy by the way, thank you!). I have a custom field (with a custom Topic Format) that I want to display on a sync'd Topic if there is a value entered in the field. But the field formatting appears even when the field is empty, which is not desirable. ^ This is the code I have added for my Topic Format for the custom field (please excuse the messy hard-coded CSS, I'm testing this thing) ^ This is the resulting display on a sync'd Topic. Notice the "Original Post Content" box there with no text underneath it. That's an empty field, nothing has been entered in the custom field so that box shouldn't be appearing at all. ^ For comparison's sake, this is what the custom field is supposed to look like when it has been filled with content/a value. Is this a bug, or am I missing some setting in the ACP like "allow for empty/no values" or something? Edited August 30, 2023 by Dreadknux
Meddysong Posted August 30, 2023 Posted August 30, 2023 Anything in that formatting box will be included in your template irrespective of whether there's a value unless you wrap it in tags which mean "if the field has a value". {{if $formValue}} Anything in here will show if the field has a value, otherwise nothing appears. {{endif}} Dreadknux and Marc 2
Dreadknux Posted August 30, 2023 Author Posted August 30, 2023 (edited) 4 minutes ago, Meddysong said: Anything in that formatting box will be included in your template irrespective of whether there's a value unless you wrap it in tags which mean "if the field has a value". {{if $formValue}} Anything in here will show if the field has a value, otherwise nothing appears. {{endif}} I thought it might be something to do with that. Sadly, I can't seem to use IF statements / IPS code in the 'Topic Format' field in ACP, as it simply outputs it as straight text. I did try including an IF in the cms > submit > topic template file in my theme, but I'm having trouble getting that to work properly either. Appreciate any other ideas? Edited August 30, 2023 by Dreadknux
Meddysong Posted August 30, 2023 Posted August 30, 2023 Oh, I've just noticed that you're speaking about a new feature! Yes, that does complicate things.
opentype Posted August 30, 2023 Posted August 30, 2023 20 minutes ago, Dreadknux said: I did try including an IF in the cms > submit > topic template file in my theme, but I'm having trouble getting that to work properly either. Yes, you can do it there. Changes there are global, but you can target the specific fields. It’s a bit tricky to try things out there as the code only takes effect when a new record is submitted. Marc 1
Dreadknux Posted August 31, 2023 Author Posted August 31, 2023 I'm just not entirely sure why the formatting for a field appears by default even when there is no data in the field. It's not logical. @Marc Stridgen is there a possibility in a future update to allow for IPS code in the 'Topic Format' section of a custom field, in the form of... {{if $formValue}} ... so that I can get around this? Alternatively, do you or any IPS staff have any ideas with what code to include in the cms > submit > topic template bit to only show fields if they have data? I'm guessing the below could work (with the 'if $field' statement) but as opentype said it's difficult for me to test directly with the way the topic sync feature works, so some steer/knowledge would be useful. {{foreach $record->topicFields() as $id => $field}} {{if $field}} {$field|raw} {{endif}} {{endforeach}} <br> <p><a href="{$record->url()}">{lang="content_view_record" sprintf="$record::database()->recordWord( 1 )"}</a></p> Thank you!!
Marc Posted August 31, 2023 Posted August 31, 2023 Feel free to add that as a suggestion in the feedback area if you would like to see changes in how this works. Unfortunately, I'm really not the person to help with code. I can move to the developers section to grab the attention of someone who knows better than I Dreadknux 1
Dreadknux Posted August 31, 2023 Author Posted August 31, 2023 37 minutes ago, Marc Stridgen said: I'm really not the person to help with code. I can move to the developers section to grab the attention of someone who knows better than I That would be great Marc, thanks - what I'm trying isn't getting me anywhere sadly.
Recommended Posts