pods icon indicating copy to clipboard operation
pods copied to clipboard

Pods Template Conditionals

Open PodsBot opened this issue 10 years ago • 11 comments

Discussion on replacing current Template Tags [if][else][/if], etc. with a non-shortcode style and adding Comparison operators to the if conditionals. Add additional items to include in this feature as we find them. Also close and reference any other issues that are similar to this request here.

Basic operators

  • [ ] {@if <conditional>}}
  • [ ] {@elseif <conditional>} - Implemented within corresponding {@if}{@/if}
  • [ ] {@else} - Implemented within corresponding {@if}{@/if}
  • [ ] {@each field_name} - Loop through values of a relationship / file / taxonomy field
  • [ ] {@each field_name orderby="field"} - Loop through values of a relationship / file / taxonomy field (with orderby)

Conditionals:

  • [ ] field_name - Non-empty value check
  • [ ] ! field_name - Empty value check
  • [ ] field_name == "Value" - Value equals check
  • [ ] field_name != "Value" - Value does not equal check
  • [ ] field_name == other_field - Value equals check on another field
  • [ ] field_name != other_field - Value does not equal check on another field
  • [ ] nth(#) - :nth-child() type of functionality - see: http://www.w3schools.com/cssref/sel_nth-child.asp
  • [ ] zebra() - Every other row in the loop

Comparison operators (numeric or compare another field): http://php.net/manual/en/language.operators.comparison.php

  • [ ] field_name == 1
  • [ ] field_name = 1 (same as above, for more complete coverage)
  • [ ] field_name != 1
  • [ ] field_name <> 1 (same as above, for more complete coverage)
  • [ ] field_name === 1
  • [ ] field_name !== 1
  • [ ] field_name < 1
  • [ ] field_name <= 1
  • [ ] field_name > 1
  • [ ] field_name >= 1

Logical Operators (with no nesting support): http://php.net/manual/en/language.operators.logical.php

  • [ ] field_name = 1 && other_field_name = 2
  • [ ] field_name = 1 AND other_field_name = 2 (same as above, for more complete coverage)
  • [ ] field_name = 1 || other_field_name = 2
  • [ ] field_name = 1 OR other_field_name = 2 (same as above, for more complete coverage)

Additional things to be figured out:

  • [ ] Date Math Comparisons against {@today}, {@cur_date}, etc.

Special tags to add into field():

  • [ ] {@_total} - Total count of the loop
  • [ ] {@_total_found} - Total Found in the result set
  • [ ] {@_position} - Current position in the loop starting at 1

PodsBot avatar Oct 08 '15 21:10 PodsBot

Follow-up, see what Metaplate can do with it's templating, how much of this can it do?

https://calderawp.com/downloads/caldera-metaplate/

sc0ttkclark avatar Oct 09 '15 13:10 sc0ttkclark

+1

codente avatar May 08 '16 04:05 codente

Those comparison operators would be very useful when creating pods templates. +1

oldrup avatar Feb 16 '17 20:02 oldrup

This format and design sounds more like Twig/Timber Templating support: https://www.upstatement.com/timber/

jimtrue avatar Jun 16 '18 10:06 jimtrue

This format and design sounds more like Twig/Timber Templating support: upstatement.com/timber

Agreed.

One extreme option, if BC is going to break anyway, would be to pull Timber in as a dependency, and just pass the Pods Template content through Timber::render() (or whatever is needed) instead. Twig is far more established as a templating language than the Pods Template language, and may also ease adoption.

Maybe allow Pods Templates to choose which templating engine it should use, so that existing sites aren't forced to update the contents of their templates, and could switch over templates one at a time when they wanted to make use of the more advanced features?

GaryJones avatar Jun 19 '18 19:06 GaryJones

@GaryJones Great idea! We would definitely want to put a "freeze" on the current iteration of Template Language handling and provide the Timber as a smoother transition path with better handling for loops and conditionals for those people that still don't want to use PHP.

The setting could either be at a Pods Admin, Settings level or on a template by template basis possibly.

Do you know if the CodeMirror library we currently use has 'code assist and syntax highlighting' for Twig/Timber templating?

jimtrue avatar Jun 19 '18 19:06 jimtrue

Anything that improves the Templates would be great - important thing to keep in mind is that the template/magic tag stuff is used in shortcodes - and one other thing - how does Gutenberg play into all of it - https://wordpress.org/gutenberg/handbook/templates/ ?

quasel avatar Jun 19 '18 20:06 quasel

Do you know if the CodeMirror library we currently use has 'code assist and syntax highlighting' for Twig/Timber templating?

I assume it's this: https://codemirror.net/mode/twig/. I'm not sure if Timber adds any more Twig-like syntax on top, which may miss the syntax highlighting.

Related reading: https://notlaura.com/the-twig-for-timber-cheatsheet/ by @laras126 who I recently met at WCEU and who may know the answer to the above :-)

GaryJones avatar Jun 19 '18 20:06 GaryJones

Templates in Gutenberg are basically pre-configured 'content blocks'. Our implementation of Templates, whether Auto Templates are placed by Shortcodes would be identical. Improvements on the process would be to identify Pods Templates based on Post Type and providing them as Template blocks to drop based on Content Type.

jimtrue avatar Jun 20 '18 01:06 jimtrue

+1 for this functionality.

fivehead avatar Mar 02 '19 19:03 fivehead

+1

abednaseri avatar Sep 28 '20 12:09 abednaseri