简体   繁体   中英

What would the TWIG equivalent of <?php the_field('field_name'); ?> be?

I'm using Wordpress with the "Advanced Custom Fields" plugin , and I'm trying to call variables from the plugin into my TWIG file.

The documentation for the plugin says to use <?php the_field('field_name'); ?> <?php the_field('field_name'); ?> in the PHP, but I can't figure out how to translate that code to TWIG.

I tried the following:

  • Running code as is (but it appears TWIG doesn't run pure PHP.)
  • {% post.the_field('my_fields_name') %} , but to no avail
  • {{ post.my_fields_name }} , but it printed/logged "Array" to the frontend.
  • {{ post.get_field('the_field', my_fields_name) }} and {{ post.get_field('the_field', 'my_fields_name') }}

Any help will be greatly appreciated

Took me a while, but ended up being an easy solution! Turns out these custom fields are stored in the meta-data, so all I had to do was {{ post.meta('my_fields_name') }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM