1

Thank you for your time and patience I'm a newbie to the Craft world. I've been all over the Craft Documentation and this site trying to figure out the best approach for a site I am putting together. The prototype I did makes sense however when it came time to put it into Craft I'm hesitant or lacking confidence in the setup. I just need a sound board to bounce off my setup.

Current Section setup:

  • Home (Single)
  • Company (Single)
  • Products (Single and Structure with multiple entry types)
    • Product Category A
      • Type A
        • Size A
        • Size B
      • Type B
      • Type C
    • Product Category B
      • Product
    • Product Category C
      • Type D
      • Type E
  • Support (Single)
  • Contact (Single)

How would I best create a template structure for the products section? How can I setup categories to help create this structure?

URL would ideally be site.com/products/product-category/product

or do I even need products? Just jump to the product-category?

I want to have a category page, comparison page (Size) and dedicated product page. The category page with the type category wouldn't need an intermediate page.

1 Answer 1

0

It's fairly straight forward. You could go with a single "layout" file and then a template file for each unique template that utilizes that simple header/footer layout

  • templates/layouts/_layout.html
  • templates/index.html (homepage)
  • templates/products.html
  • templates/support.html
  • templates/contact.html

Extending a layout:

{% extends "layouts/_layout" %}

Your product template would then just need to be coded to handle the category handle in the URL.

For instance, listing entries (products) that are assigned to a category (untested):

{# get categorySlug from URL segment 2 #}
{% set category = craft.request.getSegment(2) %}

{# get instance of category #}
{% set category = craft.categories.slug('categorySlug') %}

{# get entries related to the category instance #}
{% set entries = craft.entries.relatedTo(category) %}

{# loop through the entries #}
{% for entry in entries %}
    <a href="{{ entry.url }}">{{ entry.title }}</a>
{% endfor %}

That's obviously just an example, but should get you going in the right direction.

Related reading material:

5
  • Thank you for the reply. How would you do a two level category? E.g. product category then type or size followed by the products detail page?
    – Midknight
    Oct 31, 2016 at 20:28
  • Same idea, {% set category = craft.request.getSegment(2); set type = craft.request.getSegment(3); set size = craft.request.getSegment(4); %} Oct 31, 2016 at 20:36
  • Sorry did you mean categorySlug in that first variable declaration?
    – Midknight
    Nov 1, 2016 at 22:47
  • Well it all depends on how you structure your URL. Simply change the number to fetch the correct URL segment. (A URL segment is the text between each set of forward slashes: e.g. website.com/segment1/segment2/segment3/segment4/ Nov 1, 2016 at 23:36
  • Sorry I mean in your original response. {% set category = craft.request.getSegment(2) %} {% set category = craft.categories.slug('categorySlug') %}
    – Midknight
    Nov 2, 2016 at 3:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.