A2 Twig Templates For Custom Fields Wordpress Plugin - Rating, Reviews, Demo & Download

A2 Twig Templates For Custom Fields Wordpress Plugin - Rating, Reviews, Demo & Download
No ratings yet
Free
Follow for free plugins, new theme releases and theme news

Plugin Description

  • Use Twig template to display your post or custom post or Advanced custom fields type
  • Twig and ACF are a third-party plugin, we used them to render templates

Template requirements

  • Ensure installs of Timber plugin: https://wordpress.org/plugins/timber-library/
  • Then create a private post or page or of any post type
  • For custom post type template ensures that your template name looks like: tpl-{{post_type}}
  • or add a custom field to your post name it twig and store the template name inside it

Template Syntax: a quick guide

  • WordPress Classic Editor is preferred to edit templates
  • Use {# comments #} for comments, and comments will not render to the user,
  • and variable style is{{ field }}, it will output the data stored in your variable or custom field,
  • but for executing code; use{% if field %} check if a field has a value,
  • or{% endif %} to close the previous if condition,
  • and{% for m in meanings %} to loop over an array or repeater field called meanings using m to mention for each row
  • Inside the loop starts the subfields or array items with m.,
  • or close the loop use {% endfor %}
  • In WordPress classic editor show source and ensure there is no tags inside the template code; it is not valied to write {% endfor %}
  • For more details, see: https://twig.symfony.com/doc/2.x/

Custom Fields and ACF

  • WordPress supports custom fields, and you could add them directly to your post,
  • and ACF plugin gives more power to the custom fields
  • Use the Advanced Custom Fields plugin to take full control of your WordPress edit screens & custom field data.
  • Read more about ACF on https://wordpress.org/plugins/advanced-custom-fields/

Why templating engine and not a raw PHP programming language

  • More Simple; so templating is more readable, and very easy that allows users to learn quickly,
  • and Limit the allowed function to prevent bad mistakes,
  • and easy to edit using WordPress classic editor

About Twig templating engine

  • The twig template engine process templates data, and output a webpage.
  • and it is a flexible, fast, and secure template engine for PHP.
  • We use Twig a template language, and we allow users to modify the template design.
  • It is fast because Twig compiles templates into optimized PHP code.
  • Get flexible, so it allows the developer to define its own custom tags and filters.
  • Read more about Twig on https://twig.symfony.com

Timber and Twig

  • Timber helps to include Twig in WordPress,
  • with Timber, you write your HTML using the Twig Template Engine separate from your PHP files,
  • and this cleans up your template code so, for example, and your Twig template can focus on the HTML and display.

A2 Twig templates for Custom Fields For Developers

Add custom data to fields

  • Edit the file user-functions.php
  • Create a function and name it get_fields_{{post_type}}
  • If your custom post type contains ‘-‘ replace it with ‘_’
  • I include a sample function in user-functions.php
  • Backup your functions, and keep in mind that the file user-function may be replaced on upgrade

= Add custom data for each singular page
* Edit the file user-functions.php,
* then create a function and name it np_content_singular
* I include a sample function in user-functions.php
* Backup your functions, and keep in mind that the file user-function may be replaced on upgrade

Screenshots

No screenshots provided


Reviews & Comments