ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Nested Categories in Safecracker

August 30, 2012 8:56am

Subscribe [2]
  • #1 / Aug 30, 2012 8:56am

    RiaanZA

    8 posts

    This question may be related to a resolved thread.

    Hi there, my problem is as follows:
    Im trying to created a list child (level2) of categories within a safecracker form using the {categories} loop. So far been unsuccessful

    I’ve tried using {parent_id} in a conditional, but it doesnt seem to be available in the {categories} loop eg:

    {if parent_id == '1'}
    This is a child
    {/if}

    The reason it needs to be within the {categories} loop and not within the {exp:channel:categories} is that I need the {checked} variable.

    Any help would be appreciated

     

  • #2 / Aug 31, 2012 4:10pm

    Shane Eckert

    7174 posts

    Hey RiaanZA,

    Hmmmm .... I would think that should work.

    What version of ExpressionEngine are you currently using?

    Can I see the entire form? I will try and reproduce.

    Please let me know.

    Cheers,

  • #3 / Sep 03, 2012 3:46am

    RiaanZA

    8 posts

    Hi Shane,

    Im using EE 2.5.2.
    This is my code:

    {exp:safecracker channel="establishment" return="safecracker/ENTRY_ID" class="fm NiceIt" json="yes" entry_id="{last_segment}" include_jquery="no" id="create_owned_establishment" preserve_checkboxes="yes" }
    ...
    Some Working Form Code
    ...
    <div class="ctrls-set">
        {categories group_id="3"}
            {if parent_id == '1'}
                
                    <input type="checkbox" name="category[]" value="{cat_id}" id="tcbx_3" {checked} />
                    <label class="align" for="tcbx_3">{category_name}</label>
                
            {/if}
        {/categories}
    </div>
    
    {/exp:safecracker}

    This doesnt output any categories. When I remove the {if parent_id == '1'} conditional it prints the categories however it prints the parent and child categories. I want it to output just the children of the category with id 1. Also just printing {parent_id} in the loop outputs nothing which leads me to believe its not available.

  • #4 / Sep 04, 2012 9:59pm

    Dan Decker

    7338 posts

    Hi RiaanZA,

    SafeCracker uses the same parameters on the categories tag pair as Channel Entries.

    Try this:

    {exp:safecracker channel="establishment" return="safecracker/ENTRY_ID" class="fm NiceIt" json="yes" entry_id="{last_segment}" include_jquery="no" id="create_owned_establishment" preserve_checkboxes="yes" }
    ...
    Some Working Form Code
    ...
    <div class="ctrls-set">
        {categories show_group ="3"}
            {if parent_id == '1'}
                
                    <input type="checkbox" name="category[]" value="{cat_id}" id="tcbx_3" {checked} />
                    <label class="align" for="tcbx_3">{category_name}</label>
                
            {/if}
        {/categories}
    </div>
    
    {/exp:safecracker}
  • #5 / Sep 05, 2012 3:44am

    RiaanZA

    8 posts

    Thanks Dan, but I managed to find another solution.
    Using GW Categories (which give more flexibility when listing categories) - http://gwcode.com/add-ons/gwcode-categories, along with the plugin suggested here: http://ellislab.com/forums/viewthread/203404/ which tests if the category is assigned to the channel, I was able to solve the problem.

    <div class="ctrls-set">
        {exp:gwcode_categories cat_id="1" depth="2" group_id="3" style="linear" parse="inward"}  
                  
                <input type="checkbox" name="category[]" value="{cat_id}" id="tcbx_3" {if {exp:is_checked category_id="{cat_id}" entry_id="{entry_id}"} == 1}checked="checked"{/if} />
                <label class="align" for="tcbx_3">{cat_name}</label>
            
        {/exp:gwcode_categories}
    </div>
    </div>
  • #6 / Sep 06, 2012 3:04pm

    Dan Decker

    7338 posts

    Hi RiaanZA,

    Excellent! And I must admit, I was wrong in my reply. SafeCracker *does not* honor the same parameters as Channel Entries.

    I’m so glad to see you came to a solution that works, and thank you for sharing!

    If you need anything else, please let us know.

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases