Support Forum
Hello,
Unable to load any twig tags in views - output HTML is not recognising either the for loops or anything else. What am I doing wrong?
<table>
<tr>
<th></th>
<th>Date</th>
<th>Name</th>
<th>Location</th>
</tr>
{% for post in query.posts %}
<tr>
<td><a href="{{ post.url }}">Detail</a>
</td>
<td>{{ post.date }}</td>
<td>{{ post.name }}</td>
<td>{{ post.city }}</td>
</tr>
{% endfor %}
</table>
I should note when I try and (edit a) post I get the following errors:
Warning: array_keys() expects parameter 1 to be array, null given in /home/.../wp-content/plugins/meta-box/inc/sanitizer.php on line 154
Warning: array_intersect(): Expected parameter 2 to be an array, null given in /home/.../wp-content/plugins/meta-box/inc/sanitizer.php on line 154
Warning: Cannot modify header information - headers already sent by (output started at /home/.../wp-content/plugins/meta-box/inc/sanitizer.php:154) in /home/.../wp-includes/pluggable.php on line 1281
Hi,
Regarding the view, did you select the location Post for the view? Please see my screen record https://www.loom.com/share/98b1bd2c135c4fd2816d8cedd0ff8447, your code renders the table on the single post as well.
Regarding the warning error, please share the code that you are using to create fields. I will take a closer look and give a quick response.
I have followed this suggestion, with no output.
But I think I need a bit more explanation.
This code was intended for a view, editions-list, that lists not all posts, but only custom post type, "edition" each of which represents a post about a book. I've created this using MetaBox.
editions-list looks something like this (I've only given the first few fields):
<table>
<tr>
<th></th>
<th>Date</th>
<th>Title</th>
</tr>
{% for post in query.posts %}
<tr>
<td>Detail</td>
<td>{{ post.year }}</td>
<td>{{ post.booktitle }}</td>
</tr>
{% endfor %}
</table>
Type for editions-list is archive.
Location for editions-list is edition Archive.
I then have created a second view, single-book-view, that gives a detailed view of each book.
single-book-view looks something like this (I've only given the first few fields):
<table>
<tr>
<td>Year</td>
<td>{{ post.year }}</td>
</tr>
<tr>
<td>Title</td>
<td>{{ post.booktitle }}</td>
</tr>
</table>
Type for single-book-view is singular.
Location for single-book-view is edition / all
First code not rendering properly, it should be
<table>
<tr>
<th></th>
<th>Date</th>
<th>Title</th>
</tr>
{% for post in query.posts %}
<tr>
<td>Detail</td>
<td>{{ post.year }}</td>
<td>{{ post.booktitle }}</td>
</tr>
{% endfor %}
</table>
Hi,
Could you please go to Admin dashboard -> Settings -> Permalinks -> Save the current settings again? Then check the archive edition page or single edition page again.
I've tested your code in my local site, it works as well, see my screen record https://www.loom.com/share/7816d7cc51404da2a59c135bc0ddadc5.
Thanks for all your help on this, but it is still not working for me... The twig is not rendering at all.
Here is the source code of the rendered page:
<table>
<tr>
<th></th>
<th>Date</th>
<th>Title</th>
<th>Location</th>
</tr>
<tr>
<!-- not live so don't want to share URL publicly -->
<!-- but this produces the URL of the listing page itself, not a link to the item page -->
<td><a href="https://mysite.url/print-editions/">Detail</a>
</td>
<td><!--blank--></td>
<td><!-- should render {{ post.year }}</td>
<td><!-- should render {{ post.booktitle }} -- a custom field called 'booktitle' rather than the name of the post --></td>
<td><!-- should render {{ post.location }}--></td>
</tr>
</table>
I can provide the PHP for the post type or field group, if it helps...
Hi Michael,
Can you please share the screenshot of the view(s) screen? I think there is something that we miss in the discussion that might cause the error.
Thanks,
Anh
Here is the Views Screen:
Hi Michael,
Please follow some steps to check the view:
and it would be better if you make a screen record while doing steps with Loom then share the link here.
Hi,
Please share your admin site account via this contact form https://metabox.io/contact/. I will take a closer look and give a quick response.
Hi,
Because you've used the custom archive slug editions
so the link to the archive page is https://test-site.drmr.me/wp/editions/. This page also renders the table as well, see my screenshot https://share.getcloudapp.com/Qwull698.
Regarding the error when saving the edition post, please take a note that fields autocomplete
and image_select
require options to choice https://share.getcloudapp.com/GGuooXYQ.
For more information, please follow the documentation.
https://docs.metabox.io/fields/image-select/
https://docs.metabox.io/fields/autocomplete/