PHP Developers Network
http://forums.devnetwork.net/

Where is ct defined and how can i show records in index.twig
http://forums.devnetwork.net/viewtopic.php?f=72&t=143040
Page 1 of 1

Author:  gautamz07 [ Thu Oct 13, 2016 1:50 am ]
Post subject:  Where is ct defined and how can i show records in index.twig

How do i display a few records in bolt in my index.twig file ?

What i have done is i have just deleted the index.twig and made a new index.twig file which is pritty much a blank html document with the following code in it:

Syntax: [ Download ] [ Hide ]
{% dump(ct) %}

            {% setcontent records = ct.slug ~ "/latest/3" %}
           
            {% set records = records|order(app.config.get('general/listing_sort')) %}
           
            {% for record in records %}
                <article>

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

                    {{ popup(record.image, 1200, 500) }}

                    {# display something introduction-like.. #}
                   {% if record.introduction %}
                        {{ record.introduction }}
                    {% elseif record.teaser %}
                        {{ record.teaser }}
                    {% else %}
                        <p>{{ record.excerpt(300, false, search|default('')) }}</p>
                    {% endif %}

                    {% include 'partials/_recordfooter.twig' with { 'record': record } %}

                </article>

                {% if not loop.last %}
                    <hr>
                {% endif %}

            {% else %}
                <article>

                    <h2>{{ __('general.phrase.no-content-found') }}</h2>

                    <p>
                        {{ __("Unfortunately, no content could be found. Try another page, or go to the <a href=\"%paths_root%\">homepage</a>.", {'%paths_root%': paths.root} ) }}
                    </p>

                </article>
            {% endfor %}
 



As of now when i load the file , and check in the browser i see the content in the else clause displayed . Now at the start of the code i have the below lines of code:

Syntax: [ Download ] [ Hide ]
{% dump(ct) %}

{% setcontent records = ct.slug ~ "/latest/3" %}
           
{% set records = records|order(app.config.get('general/listing_sort')) %}
 


But the problem is when i dump ct it shows me null in the Browser. And when i check any other template in the default theme i don't see ct defined using setcontent :(

as you can see records is defined HERE https://github.com/bolt/bolt/blob/relea ... e.twig#L61


But where is ct defined ??

Author:  Celauran [ Thu Oct 13, 2016 7:00 am ]
Post subject:  Re: Where is ct defined and how can i show records in index.

I don't understand. It's defined in the line above the one you highlighted. for ct in...

Author:  gautamz07 [ Sat Oct 15, 2016 3:06 am ]
Post subject:  Re: Where is ct defined and how can i show records in index.

Huh ....... maybe i am not seeing things right :| , but can you tell me where exactly it is defined , i mean highlight the line ?

BTW , i saw the below line on another forum and it helped me iterate over and display all my enties on the homepage :D so problem solved :D

Syntax: [ Download ] [ Hide ]
{% setcontent entries = "entries/latest/6" allowpaging %}
{% for entry in entries %}
{% endfor %}
 


But i still can't understand where ct is defined .

P.S. sorry for my irritating questions :P

Author:  Celauran [ Sat Oct 15, 2016 7:08 am ]
Post subject:  Re: Where is ct defined and how can i show records in index.


Author:  gautamz07 [ Sun Oct 16, 2016 4:55 pm ]
Post subject:  Re: Where is ct defined and how can i show records in index.

Hey sorry celauran .

I was searching everywhere to see something like

Syntax: [ Download ] [ Hide ]
setcontent ct ...
 


since i taught variable get defined using setcontent , i totally would't guess the below line was the definition of ct

Syntax: [ Download ] [ Hide ]
 {% for ct in app.config.get('contenttypes') if not ct.viewless|default(false) %}
 


Thanks though. I'll go read about more about twig and bolt and try and ask more intelligent questions :D :D

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/