Category drop down - show selected category as 'selected' using category from URL

  • Hey guys,


    Ive got a category drop down on my page using the following:


    PHP
    1. <?php
    2. PerchSystem::set_var('page_cat', perch_get('cat'));
    3. perch_categories(array(
    4. 'set' => 'community',
    5. 'template' => 'com_cat_dropdown.html',
    6. 'filter' => 'catParentID',
    7. 'match' => 'eq',
    8. 'value' => 0
    9. ));
    10. ?>

    and in my com_cat_dropdown.html


    I'd like to have the drop down remain on the selected category when on the chosen page, hence trying to parse in the category from the URL using the PerchSystem::set_var.

    Can anyone point me in the right direction to achieve this please?

  • drewm

    Approved the thread.
  • Hell xenowebdev


    Assuming perch_get('cat') gets you the catSlug, you can use conditional tags to check which category is selected and add the selected attribute to the matching <option> tag:


    HTML
    1. <perch:if id="page_cat" match="eq" value="{catSlug}">selected</perch:if>
    HTML
    1. <option value="/community/<perch:category id="catSlug" type="slug" for="catTitle" />/" <perch:if id="page_cat" match="eq" value="{catSlug}">selected</perch:if>>
    2. <perch:category id="catTitle" type="smarttext" />
    3. </option>