PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue May 23, 2017 3:39 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Nov 01, 2016 3:29 am 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 317
I have a new difficulty :P , just need some help with this. I have the following lines of code in my aside.twig file:

Syntax: [ Download ] [ Hide ]
    {% for ct in app.config.get('contenttypes') if not ct.viewless|default(false) %}
   
                {% setcontent records = ct.slug ~ "/latest/3" %}
   
                <h5>{{ __('contenttypes.generic.recent', {'%contenttypes%': ct.slug}) }}</h5>
                <ul>
                    {% for record in records %}
                        <li><a href="{{ record.link }}">{{ record.title }}</a></li>
                    {% else %}
                        <li>{{ __('contenttypes.generic.no-recent', {'%contenttype%': ct.slug}) }}</li>
                    {% endfor %}
                </ul>
                <p><a href="{{ paths.root }}{{ct.slug}}">{{ __('contenttypes.generic.overview',{'%contenttypes%': ct.slug}) }} &raquo;</a></p>
   
   
            {% endfor %}


This basically iterates over all the contenttypes in my `contenttypes.yml` file and i get the following in front end:

http://imgur.com/a/6eDfN

Now what i want is only recent entries, so i tried modifying the following line of code:

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


To the following:

{% for ct in app.config.get('contenttypes') if not ct.viewless|default(false) and app.config.get('contenttypes') == "entries" %}

But i get an error , so how exactly do i modify the following line of code:

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


So that i get only the records of "entries" contenttype ??

Thank you.
Gautam.


Top
 Profile  
 
PostPosted: Tue Nov 01, 2016 6:47 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6243
Location: Montreal, Canada
https://docs.bolt.cm/3.1/templating/content-fetching

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Tue Nov 01, 2016 12:14 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 317
Thanks celauran :)


Top
 Profile  
 
PostPosted: Tue Nov 01, 2016 12:41 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 317
I have actually referenced this doc a few times , sorry i did't know why it skipped me :( . For now i have removed the for loop and just added the below lines of code:

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

            {# {% if ct.name == 'Entries' %} #}
           {% setcontent records = "Entries/latest/3" %}
                {# {% else %} #}
                   {# {% return; %} #}
           {# {% endif %} #}


            <h5>{{ __('contenttypes.generic.recent', {'%contenttypes%': ct.slug}) }}</h5>
            <ul>
                {% for record in records %}
                    <li><a href="{{ record.link }}">{{ record.title }}</a></li>
                {% else %}
                    <li>{{ __('contenttypes.generic.no-recent', {'%contenttype%': ct.slug}) }}</li>
                {% endfor %}
            </ul>
            <p><a href="{{ paths.root }}{{ct.slug}}">{{ __('contenttypes.generic.overview',{'%contenttypes%': ct.slug}) }} &raquo;</a></p>

        {# {% endfor %} #}
 


Top
 Profile  
 
PostPosted: Tue Nov 01, 2016 2:26 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6243
Location: Montreal, Canada
Why are you doing this in the template anyhow? Makes more sense (and cleaner code!) in the controller.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Tue Nov 01, 2016 3:37 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 317
@celauran the way it is in the default theme is there is this _master.twig file, which has the following code:

Syntax: [ Download ] [ Hide ]
 {% if theme.layout.aside == "right" %}
     {{ include('partials/_aside.twig') }}
 {% endif %}


and then in the _aside.twig file there is the folliowing:

Syntax: [ Download ] [ Hide ]
<div class="panel">
    {# The next section attempts to fill the panel in the sidebar with the contents of the
      'about-us'-block, if it exists. First, attempt to fetch the block with slug 'about-us' #}
   {% setcontent block = "block/about-us" %}
    {# check if we have a title. If so, we know we have content to display. Otherwise, we will output a default text, telling the user to create the 'blocks' in the backend. #}
   {% if block.title is defined %}

        <h5>{{ block.title }}</h5>
        {{ block.content }}
        {% if link(block.contentlink) or block.editlink() %}
            <p>
                {{ link(block.contentlink, __('general.phrase.read-more')) }} /
                <a href="{{ block.editlink() }}">{{ __('general.phrase.edit') }}</a>
            </p>
        {% endif %}

    {% else %}

        <h5>{{ __('general.phrase.missing-about-page') }}</h5>

        <p>{{ __('general.phrase.missing-about-page-block') }}</p>

    {% endif %}

</div>
 



I am just basically trying to modify the default theme to suit my requirements , I am not quite familiar 100% with MVC , but do you have a more efficient way to do this ?

P.S. some of the code i post might make your eyes bleed :P sorry about that , i do intend on focusing on efficiency as i keep learning.

Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group