Custom Fields
Re-Envisioned
Support MB Views no twig tags rendering

  • Creator
    Topic
  • #20332
    Resolved MR MICHAEL BRIORDAN
    Participant

    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>
Viewing 10 replies - 1 through 10 (of 13 total)
  • Author
    Replies
  • #20333
    MR MICHAEL BRIORDAN
    Participant

    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

    #20335
    Long Nguyen
    Moderator

    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.

    #20342
    MR MICHAEL BRIORDAN
    Participant

    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

    #20343
    MR MICHAEL BRIORDAN
    Participant

    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>
    #20345
    Long Nguyen
    Moderator

    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.

    #20357
    MR MICHAEL BRIORDAN
    Participant

    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…

    #20361
    Anh Tran
    Keymaster

    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

    #20366
    MR MICHAEL BRIORDAN
    Participant

    Here is the Views Screen:

    Views Screen

    Views Screen on Snipboard

    #20367
    MR MICHAEL BRIORDAN
    Participant

    That was this listings view.

    And this is the single view:

    Views screen - singular

    Views Screen (singular)

    #20370
    Long Nguyen
    Moderator

    Hi Michael,

    Please follow some steps to check the view:

    • Deactivate all plugins except Meta Box and Meta Box AIO.
    • Move to trash all View items that you created.
    • Create new views and set location for Single Edition, Archive Edition pages again.
    • Switch to the default theme of WordPress Twenty Nineteen (optional).

    and it would be better if you make a screen record while doing steps with Loom then share the link here.

Viewing 10 replies - 1 through 10 (of 13 total)
  • You must be logged in to reply to this topic.