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

Discussion for various published PHP frameworks, including Zend Framework, CodeIgniter, Kohana, CakePHP, Yii, Symfony, and others.

Moderator: General Moderators

Post Reply
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

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

Post 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 ??
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post by Celauran »

I don't understand. It's defined in the line above the one you highlighted. for ct in...
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

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

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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.
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

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

Post 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
Post Reply