• Resolved customwebkzn

    (@customwebkzn)


    Hi,

    I’m trying to creating a school reports system with certain subjects for certain grades. The logic I’ve used is 1) if term mark is filled then display the block, and within that block if further fields are filled then display those too. I’m sure this is wrong as the title is not displaying: could you kindly advise how to achieve this?

    Here is my template code:

    [if natural_science_term_mark]
    {@natural_science_title}
    [if natural_science_year_mark] Yr {@natural_science_year_mark}[/if]
    [if natural_science_exam_mark] Exam {@natural_science_examination_mark}[/if]
    [if natural_science_class_average] Avg {@natural_science_class_average}[/if]
    [if natural_science_term_mark] Term {@natural_science_term_mark}[/if]
    {@natural_science_teacher_comment}
    [/if]

    If i omit the secondary IFs then it works but then it displays those 4 fields whether they’re filled or not.

    Thanks.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter customwebkzn

    (@customwebkzn)

    Plugin Contributor Jim True

    (@jimtrue)

    Nested IF’s are not supported in Pods Templates. If you need this kind of support, you should probably be using PHP Theme Templates.

    This is a planned support but it will require a complete overhaul of the Pods Templates as they exist at present, since the Template Tags ‘mirror’ a shortcode style, but aren’t shortcodes.

    Thread Starter customwebkzn

    (@customwebkzn)

    Hi Jim,

    Ok thanks. I managed to get it to work with nested IFs so that’s a bit strange :). Do you have a timeframe on when it be officially supported?

    Plugin Contributor Jim True

    (@jimtrue)

    We are going to have to completely overhaul the Pods Template system (it’s written on some very frightening regex’s that parse the ‘template tags’ and then turn them into shortcodes, so we’re throwing out that entire system and switching to Twig/Timber Templating since it’s more supported (and more people are familiar with it). That will allow if with conditionals, etc. and will give most people what they are looking for. It won’t happen until after 2.8 (Gutenberg release) unless folks are willing to feature fund it.

    When you say you “managed to get it to work with nested IF’s” What did you change from the above to make it work?

    Thread Starter customwebkzn

    (@customwebkzn)

    Then I should keep this version for posterity because it’s working fine now! My installation was buggy so I started from scratch. I’m using ACF 5.7.7 and Pods 2.7.9. Each subject is a field group, and not all sub fields are entered to all posts hence the nested IFs. There’s probably a much more elegant solution but this was just a quick proof of concept.

    Here is my working code:

    [if eng_teacher_comment]
    <div style=”width:48%;margin:1%;float:left;min-height:110px;”>
    <div style=”min-width:100px;float:left;font-weight:bold;”>ENGLISH</div>

    [if eng_year_mark]<div style=”float:right;padding-left:10px;font-weight:bold;”>Yr {@eng_year_mark}</div>[/if]
    [if eng_exam_mark]<div style=”float:right;padding-left:10px;font-weight:bold;”>Exam {@eng_exam_mark}</div>[/if]
    [if eng_class_average]<div style=”float:right;padding-left:10px;font-weight:bold;”>Avg {@eng_class_average}</div>[/if]
    [if eng_term_mark]<div style=”float:right;padding-left:10px;font-weight:bold;”>Term {@eng_term_mark}</div>[/if]
    <span style=”display:inline-block;text-align:justify;”>{@eng_teacher_comment}</span>
    </div>
    [/if]

    Plugin Contributor Jim True

    (@jimtrue)

    This doesn’t actually look that much different from your initial one. I know that nested [each][/each] is not supported, but maybe nested [if field][/if] are.

    Whatever currently works will continue to work, we just will stop all development in that area and suggest people switch to the new format when we add in Twig/Timber Templates. Much like folks who are classic switching to gutenberg, but less drastic.

    Thread Starter customwebkzn

    (@customwebkzn)

    If the format is as simple as this it will be a welcome change. Thanks for taking the time to reply.

    Plugin Contributor Jim True

    (@jimtrue)

    Well, not exactly as simple as our current Templates, but similar in style and functionality and we’d be able to take advantage of the CodeMirror code completer to help you guys add loop blocks and stuff like that.

    I find nested shortcodes (especially when you start throwing them in with Visual Composer or other shortcodes) just impossible to read. All the Timber/Twig stuff uses the {{ and }} style so it’s easy to find them in your Template.

    We’ll have to do something similar for the Gutenberg Blocks (both input screen blocks and ‘preformatted blocks of custom content, etc.’ blocks that you folks will be wanting to use when Gutenberg gets rolling.

    Plugin Contributor Jim True

    (@jimtrue)

    Quick question to the above: You mentioned that these are in subject Field Groups with ACF. Does that mean you’re using our if/then, etc. language with the ACF fields as well?

    Thread Starter customwebkzn

    (@customwebkzn)

    No, just what’s there, a simple if field has content then display.

    Plugin Contributor Jim True

    (@jimtrue)

    Thanks for that update ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Nested IF’ is closed to new replies.