Can any one tell me what is wrong with this twig template?

A forum for Bolt related questions / issues

Can any one tell me what is wrong with this twig template?

Postby anonymoose » Wed Jan 16, 2013 11:58 pm

I am trying to loop over an image array in my 'listing.twig' template and for some reason nothing is happening inside the loop.

Here is the template, if you can spot anything that may be causing this please speak up! Thanks!

Code: Select all
{% include '_header.twig' %}


{% for record in records %}
<article>
    {% if record.image!="" %}
        <div class='imageholder'><img src="{{ record.image|thumbnail(120, 120) }}">
        </div>
    {% endif %}


    {% for image in record.images %}
        {{ image.filename }}
        <a href="{{ image.filename }}" title="{{ image.title }}">{{ image.title }}</a><br />
    {% endfor %}

    <h2><a href="{{ record.link }}">{{ record.title }}</a></h2>
   
    {{ record.html }}

</article>
{% endfor %}

{% include '_footer.twig' %}
anonymoose
 
Posts: 20
Joined: Mon Jan 07, 2013 4:35 pm

Re: Can any one tell me what is wrong with this twig templat

Postby Bob » Tue Jan 22, 2013 9:46 pm

My first guess is that the 'images' in your contenttype is named differently. Could you post the relevant section of your contenttypes.yml ?

And a general tip, make sure to check what's in the 'record': use {{ print(record) }} to see the available fields.
Bob
Lead Developer
 
Posts: 1374
Joined: Tue Nov 20, 2007 11:16 pm

Re: Can any one tell me what is wrong with this twig templat

Postby anonymoose » Tue Jan 29, 2013 7:41 am

This seems to be a problem that occurs when trying to loop over an imagelist. The list is returned as an array of objects like so when i print()

str(1569) "[{"filename":"2013-01/Cards_01.jpg","title":"2013-01/Cards_01.jpg","id":0,"order":1},{"filename":"2013-01/Cards_05.jpg","title":"2013-01/Cards_05.jpg","id":1,"order":1},{"filename":"2013-01/Cards_07 (1).jpg","title":"2013-01/Cards_07 (1).jpg","id":2,"order":1},{"filename":"2013-01/Cards_13 (1).jpg","title":"2013-01/Cards_13 (1).jpg","id":3,"order":1},{"filename":"2013-01/Cards_14 (1).jpg","title":"2013-01/Cards_14 (1).jpg","id":4,"order":1},{"filename":"2013-01/Cards_15 (1).jpg","title":"2013-01/Cards_15 (1).jpg","id":5,"order":1},{"filename":"2013-01/Cards_16 (1).jpg","title":"2013-01/Cards_16 (1).jpg","id":6,"order":1},{"filename":"2013-01/Cards_03.jpg","title":"2013-01/Cards_03.jpg","id":7,"order":1},{"filename":"2013-01/Cards_02.jpg","title":"2013-01/Cards_02.jpg","id":8,"order":1},{"filename":"2013-01/Cards_04.jpg","title":"2013-01/Cards_04.jpg","id":9,"order":1},{"filename":"2013-01/Cards_06.jpg","title":"2013-01/Cards_06.jpg","id":10,"order":1},{"filename":"2013-01/Cards_09.jpg","title":"2013-01/Cards_09.jpg","id":11,"order":1},{"filename":"2013-01/Cards_11.jpg","title":"2013-01/Cards_11.jpg","id":12,"order":1},{"filename":"2013-01/Cards_10.jpg","title":"2013-01/Cards_10.jpg","id":13,"order":1},{"filename":"2013-01/Cards_12.jpg","title":"2013-01/Cards_12.jpg","id":14,"order":1},{"filename":"2013-01/Cards_08.jpg","title":"2013-01/Cards_08.jpg","id":15,"order":1},{"filename":"2013-01/Cards_18.jpg","title":"2013-01/Cards_18.jpg","id":16,"order":1},{"filename":"2013-01/Cards_19 (4).jpg","title":"2013-01/Cards_19 (4).jpg","id":17,"order":1}]"


Regardless, here is the contenttypes file as well:

# This file defines the contenttypes on the website. See the documentation for
# details: http://docs.bolt.cm/content#defining-contenttypes


pages:
name: Pages
singular_name: Page
fields:
title:
type: text
class: large
slug:
type: slug
uses: title
image:
type: image
body:
type: html
height: 300px
template:
type: templateselect
filter: '*.twig'
taxonomy: [ chapters ]
sort: title
recordsperpage: 100

works:
name: Works
singular_name: Work
fields:
title:
type: text
class: large
slug:
type: slug
uses: title
image:
type: image
pesos:
type: imagelist
html:
type: html
height: 150px
video:
type: video
file:
type: file
template:
type: templateselect
filter: '*.twig'
taxonomy: [ categories, tags ]
sort: title
recordsperpage: 100


# possible field types:
# text - varchar(256) - input type text.
# integer - integer - Input field for integer numbers.
# float - double - Input field for floating numbers, stored as 'Double'.
# geolocation - text (65kb) - Input field for geolocation. Enter an address, and the location is geocoded to latitude/longitude coordinates
# imagelist - text (65kb) - Input type for imagelists. Add multiple images with a description. Useful for image sliders, galleries, etcetera.
# image - varchar(256) - image select/upload widget, stored as filename.
# file - varchar(256) - file select/upload widget, stored as filename.
# video - varchar(256) - Video embed widget, stored as filename.
# html - text (65kb) - wysiwyg element.
# textarea - varchar(32768) - Simple, plain < textarea > field.
# datetime - datetime - date and time selector widget.
# date - datetime - date selector widget.
# templateselect - varchar(256) - select with template filenames


# number (deprecated) - input type decimal(18,9), useful for storing number that need to be sortable
anonymoose
 
Posts: 20
Joined: Mon Jan 07, 2013 4:35 pm

Re: Can any one tell me what is wrong with this twig templat

Postby Bob » Tue Jan 29, 2013 9:25 pm

Which Bolt version are you using? I think this issue has been solved already.
Bob
Lead Developer
 
Posts: 1374
Joined: Tue Nov 20, 2007 11:16 pm

Re: Can any one tell me what is wrong with this twig templat

Postby anonymoose » Wed Jan 30, 2013 3:42 am

My current install is 0.9.2
anonymoose
 
Posts: 20
Joined: Mon Jan 07, 2013 4:35 pm

Re: Can any one tell me what is wrong with this twig templat

Postby anonymoose » Wed Jan 30, 2013 5:54 am

When I echo with:

Code: Select all
{{ record.images }}


here is what is returned:

Code: Select all
[{"filename":"2013-01/01_Program (2).jpg","title":"2013-01/01_Program (2).jpg","id":0,"order":1},{"filename":"2013-01/02_Program Print Specs (1).png","title":"2013-01/02_Program Print Specs (1).png","id":1,"order":1},{"filename":"2013-01/03_Program Pages (1).jpg","title":"2013-01/03_Program Pages (1).jpg","id":2,"order":1}]


It seems to me that bolt doesn't have a handler built into the loop functionality to handle the array of objects here. Is this assumption correct? Let me know if this helps in figuring out why the loop isn't working.

Thanks for the help so far!
anonymoose
 
Posts: 20
Joined: Mon Jan 07, 2013 4:35 pm

Re: Can any one tell me what is wrong with this twig templat

Postby anonymoose » Wed Jan 30, 2013 5:56 am

When I echo with:

Code: Select all
{{ record.images }}


here is what is returned:

Code: Select all
[{"filename":"2013-01/01_Program (2).jpg","title":"2013-01/01_Program (2).jpg","id":0,"order":1},{"filename":"2013-01/02_Program Print Specs (1).png","title":"2013-01/02_Program Print Specs (1).png","id":1,"order":1},{"filename":"2013-01/03_Program Pages (1).jpg","title":"2013-01/03_Program Pages (1).jpg","id":2,"order":1}]


It seems to me that bolt doesn't have a handler built into the loop functionality to handle the array of objects here. Is this assumption correct? Let me know if this helps in figuring out why the loop isn't working.

Thanks for the help so far!
anonymoose
 
Posts: 20
Joined: Mon Jan 07, 2013 4:35 pm

Re: Can any one tell me what is wrong with this twig templat

Postby Bob » Thu Jan 31, 2013 10:41 pm

If you update to the latest version (0.9.8, at the moment), this should be fixed. :-)
Bob
Lead Developer
 
Posts: 1374
Joined: Tue Nov 20, 2007 11:16 pm


Return to Bolt Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron