Where to learn Twig for WordPress / {% set args %} - hierarchical CPTs
- This topic has 2 replies, 3 voices, and was last updated 3 years, 8 months ago by
webdev.
-
AuthorPosts
-
July 10, 2021 at 7:56 AM #29404
AMX
ParticipantHi guys,
I think that Twig is absolutely fantastic and I really want to learn it. However, I have great difficulty finding Twig code examples related to WordPress and Metabox, except for the basic stuff.
The documentation is quite limited.- You link to the official documentation of Twig on symfony.com, however in the context of WordPress it is not so useful. Basically, it's like a GRAMMAR of a language, but it lacks the specific "VOCABULARY" related to WordPress. Without the "vocabulary" used in the context of WordPress/Metabox, it's difficult for me to master it. Is there some more detailed reference with code examples, that I haven't been able to find?
- Is the implementation of Twig in Metabox compatible with Timber, so that their documentation can be applied to Metabox? I tried some things from there and they didn't work for me.
- At the moment, I would like to learn how to filter a loop query of CPTs.
The CPTs are hierarchical and I would like to display all posts that have a parent post of the same type. For example, there is a CPT called "places" with such posts:
<br>
<br>
/japan/
/japan/tokyo
/japan/yokohama
/australia/
/australia/sydneyIn the loop, I would like to display "Tokyo", "Yokohama", "Sydney" but NOT "Japan" and "Australia".
Also, I would like to show only posts which have a checkbox checked.I suppose it is done through this:
{% set args = { post_type: 'places', posts_per_page: -1 } %}
{% set posts = mb.get_posts( args ) %}I just cannot find out how to filter the query by the parent/child status and checkbox status...
I would not like to bother the support with basic questions, but it's not easy to find such answers about Twig in the documentation or elsewhere on the Internet. I have spent hours searching, but the online materials about Twig in relation to WordPress & Metabox are very scarce. It's quite difficult to find the required "vocabulary" for slightly more advanced tasks.
Greetings,
TomJuly 10, 2021 at 4:12 PM #29415Long Nguyen
ModeratorHi,
At first, you should have basic knowledge about WordPress functions https://codex.wordpress.org/Function_Reference
The View helps us to get the returned data from a WordPress or PHP function and show it via the Twig Template Engine. You can read more on Timber document https://timber.github.io/docs/
September 3, 2021 at 2:00 AM #30559webdev
ParticipantHi,
I'd like to echo OPs good feelings about Twig in general, and I really like it's use in Metabox Views, but I also find it a bit confusing to know where to find relevant documentation.
For example, on the Timber docs you've linked, there is a reference to a number of functions in the URLHelper section: https://timber.github.io/docs/reference/timber-urlhelper/
Unfortunately, none of them seem to work,
For example if I put {{mb.var_dump(mb.get_current_url()}} in my View, the return is NULL.
Same with all of the URL helper functions on there as far as I can tell.
Can you give a bit more detail about what parts of Twig/Timber will and won't work? -
AuthorPosts
- You must be logged in to reply to this topic.