Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Listing page with dynamic tag

solved

Started by Mat 7 years ago · 5 replies · 746 views
7 years ago

Hello,

I have a page with a description of one machinery, main content is the description, after this I have two section, first with features and second with optionals. These sections are cards dynamically created picking infos from page with particular tags. For example, the cards of feature, are chosen from pages with tag 'features' and 'model_name'... all works, but I need the tag 'model_name' will be dynamic, will be the same tag used for model page.

How I can do this? Thanks for any suggestions...

7 years ago

Hi,
Are you still looking for the solution? It will be easier to help you if you post the code you've already got.

7 years ago

Hi, thanks for suggestion!

this is the section in product page with "features" tagged items:

TWIG
   <div class="p-4">
        <div class="owl-carousel owl-theme">
        {% for post in taxonomy.findTaxonomy({'category':'features','tag':'thisproductmodel'}).order('date', 'desc') %}
        <div>
        {% set image = post.media.images|first %}
            {% if image %}
            <img src="{{ image.url }}" class="img-responsive img-fit-cover">
            {% endif %}
        <blockquote>
            <p class="text-justify">{{ post.content }}</p>
            <cite>{{ post.title }}</cite>
        </blockquote>
        </div>
        {% endfor %}                
        </div>
 </div>

at the end of page, I use this:

TWIG
<div id="tags">
    <div class="container grid-xl vertical-padding">
        <hr>
        <p class="text-gray text-right">Categories: 
        {% for tag in page.taxonomy.tag %}
            <a class="chip" href="search/tag:{{ tag }}">{{ tag }}</a>
        {% endfor %}
        </p>
    </div>
</div>

and I need the tag used for this last section (the tag identify this product), will be used automatically in features section.

To be more precise, in Taxonomies, the page have one categories productcategory and two tag, brandname and productmodel

Thanks

7 years ago

Not tested, but you can do something like that:

TWIG
{% for post in taxonomy.findTaxonomy({'category':'features','tag':page.taxonomy.tag|first}).order('date', 'desc') %}

This will use the first tag as product model for this machinery. The problem is taht this solution assume that the product model is always the first tag. You can of course choose to use the last tag, or any other tag, but this solution will constrain you to always define your tags in the same order. This seems quite error-prone.

Better, I suggest to create custom taxonomies instead of using the tags. As explained here put something like this in your site.yaml:

TXT
taxonomies: [category,tag,brandname,productmodel]

Then,

  • in your machinery page:
    YAML
    ---
    taxonomy:
    productmodel: "Toaster XYZ"
    brandname: "Some brand"
    ---
    
  • in your feature pages:
    YAML
    ---
    taxonomy:
    category: features
    productmodel: "Toaster XYZ"
    ---
    
  • in the template:
    TWIG
    {% for post in taxonomy.findTaxonomy({'category':'features','productmodel':page.taxonomy.productmodel}).order('date', 'desc') %}
    
7 years ago

Another solution, among others, may be:

  • in site.yaml:
    TXT
    taxonomies: [category,tag,feature_for]
    
  • in your machinery page:
    YAML
    ---
    title: "Toaster XYZ"
    ---
    
  • in your feature pages:
    YAML
    ---
    taxonomy:
    feature_for: "Toaster XYZ"
    ---
    
  • in the template:
    TWIG
    {% for post in taxonomy.findTaxonomy({'feature_for':page.title}).order('date', 'desc') %}
    
7 years ago

Many thanks lilive!

I added two taxnomies, "brand" and "model", as result now I have:

TWIG
{% for post in taxonomy.findTaxonomy({'category':'features','model':page.taxonomy.model}).order('date', 'desc') %}

An everything works perfect!

👍

last edited 08/28/19 by Mat

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 54 12 hours ago
Support · by Anna, 3 days ago
2 60 15 hours ago
Support · by Justin Young, 15 hours ago
1 30 15 hours ago
Support · by Duc , 1 week ago
2 65 5 days ago
Support · by Colin Hume, 1 week ago
2 57 5 days ago