How to display the name of the category ?

  • I have spent hours trying to get this simple function working, and have looked deep into this forum and all the docs but there's just insufficient examples online, and also some broken links in the docs!


    I am creating a shop without e-commerce functionality.. so basically a catalogue shop. I am using the shop app also.


    I have created a set named Furniture, and within this set there are a number of categories such as tables, chairs etc.


    My site is structured as:


    website.com/products.php

    • On this page it displays all the categories in the Furniture set. User needs to select a category to browse products.


    PHP
    1. <h1> Select a Category </h1>
    2. <?php perch_categories([
    3. 'set' => 'furniture',
    4. 'template' => 'furniture_list.html',
    5. ]);
    6. ?>


    • This is the furniture_list.html :


    Code
    1. <h6>
    2.     <a href="products/furniture.php?cat=<perch:category id="catSlug">">
    3.         <perch:category id="catTitle" type="smarttext" label="Title" required="true" />
    4.     </a>
    5. </h6>


    • So the above is working well (I hope I have set that up correctly as I am quite new to perch). I am able to select the category 'Tables' for example.
    • Once I select 'Tables' , I am now on the furniture.php page.


    website.com/products/furniture.php?cat=tables

    • This page is displaying all the products that have the 'tables' category assigned to them using the products settings.
    PHP
    1. <?php
    2. perch_shop_products([
    3.      'template' => 'products/product_list.html',
    4.         'variants' => true,
    5.         'count' => 10,
    6.         'sort' => 'price',
    7.         'category' => 'furniture/'.perch_get('cat'),
    8.     ]);
    9. ?>
    • Products are displaying well, but the problem I am having is getting the category title to display on the page.
    • I am trying to get 'Tables' to display at the top of my page as a <h1> which is the category we are currently on.


    Would anyone have any suggestions of what I can try?


    Thanks

  • drewm

    Approved the thread.
  • You can use the data option to pass extra variables into your template

    Should work, but if the perch_shop_products function doesn't accept the data option, its just a shortcut for the following,

    Code
    1. PerchSystem::set_var('categoryTitle', perch_get('cat'));