Page 1 of 1

Where is ct defined and how can i show records in index.twig

Posted: Thu Oct 13, 2016 1:50 am
by gautamz07
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:

Code: Select all

{% 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:

Code: Select all

{% 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 ??

Re: Where is ct defined and how can i show records in index.

Posted: Thu Oct 13, 2016 7:00 am
by Celauran
I don't understand. It's defined in the line above the one you highlighted. for ct in...

Re: Where is ct defined and how can i show records in index.

Posted: Sat Oct 15, 2016 3:06 am
by gautamz07
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

Code: Select all

{% 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

Re: Where is ct defined and how can i show records in index.

Posted: Sat Oct 15, 2016 7:08 am
by Celauran
gautamz07 wrote:Huh ....... maybe i am not seeing things right :| , but can you tell me where exactly it is defined , i mean highlight the line ?
https://github.com/bolt/bolt/blob/relea ... e.twig#L59
Literally the line right above. It's like you're not even trying.

Re: Where is ct defined and how can i show records in index.

Posted: Sun Oct 16, 2016 4:55 pm
by gautamz07
Hey sorry celauran .

I was searching everywhere to see something like

Code: Select all

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

Code: Select all

 {% 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