Page 1 of 1

How do i pass the categories varaible from the home page

Posted: Thu Nov 17, 2016 4:53 pm
by gautamz07
I think i have asked this question before , but somehow i have still now been able to achieve or solve this , hence i will ask again:

I want three boxes on my home page in my bolt-cms and when clicked on these 3 boxes i would like that whatever that box category is , a new page opens with only the articles related to that particular category .... now i have't yet been able to figure how exactly this would work , i mean i have the idea in my mind , but just can't get it to join togeather , so i know that the below line of code:

Code: Select all

{% setcontent travelpages = 'pages' where { categories: 'travel' } %}
Will give me only all the articles related to travel ... and the below line code:

Code: Select all

{% setcontent codingpages = 'pages' where { categories: 'coding' } %}
will only give me all the categories related to coding ....

now , I suppose i would have a template that looks like the below:

Code: Select all

{% setcontent records = 'pages' where { categories: $categories } %}
                    
                    {% for record in records  %}
                        <div class="col-md-4">
                            <figure class="hm-page-blog-post-preview">

                                {# <img src="{{ thumbnail(record.image|image, 200, 200)  }}" alt=""> #}
                                {# <img src="{{ thumbnail(record.image|image, 200, 200)  }}" alt=""> #}
                                <img src="{{ record.image|image }}" alt="">

                                <figcaption>
                                    {# DIFF:: What is popup and what does the below line do  #}
                                    {# {{ popup(record.image, 1200, 500) }} #}
                                    <h2><a href="{{ record.link }}">{{ record.title }}</a></h2>
                                    {% if record.introduction %}
                                        {{ record.introduction }}
                                    {% elseif record.teaser %}
                                        {{ record.teaser }}
                                    {% else %}
                                        <p>{{ record.excerpt(300, false, search|default('')) }}</p>
                                    {% endif %}
                                </figcaption>

                            </figure>


                        </div>

                    {% 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 %}
Check the 1st line of code:

Code: Select all

{% setcontent records = 'pages' where { categories: $categories } %}

The variable

Code: Select all

$categories
is what gets passed from the previous template as the particular category ... but how do i exactly pass the variable from the main template ??

I believe the 3 boxs on the home page will be <a> tags , and but what exactly do i add in the href ???

I hope what i'am saying makes sense . Basically what i want is what is what do i add in the href of the <a> tags on the homepage and how do i pass the $categores variable to the next template that will load when i click on the <a> tags ??

Re: How do i pass the categories varaible from the home page

Posted: Fri Nov 18, 2016 8:10 am
by Celauran
Have you implemented any custom routes? You could then easily pass the parameter into your controller and build your query accordingly.