0

I was wondering if someone can tell me how to approach this. I have some code that runs through all available entries within a channel and determine if its a match to the pre-determined variable. I can output the matches fine but I want to display a standard form if there is no match.

Here is my code so far

{exp:channel:entries channel="dynamic_activity" dynamic="no" author_id="CURRENT_USER"}

    {exp:switchee variable = "{related_activity_id}/{related_adventure_id}" parse="inward"} 
        {case value="{embed:related_activity_id}/{embed:related_adventure_id}"}
            {exp:safecracker 
                channel="dynamic_activity" 
                return="/admin/story/"
                use_live_url="no"
                error_handling=“inline” 
                preserve_checkboxes=“yes” 
                include_jquery="no" 
                author_id="CURRENT_USER"
                entry_id="{entry_id}"
            }
                <input type="text" name="title" id="title" value="{title}">
                <input type="text" name="related_adventure_id" id="related_adventure_id" value="{related_adventure_id}">
                <input type="text" name="related_activity_id" id="related_activity_id" value="{related_activity_id}">
                <input type="text" name="childs_name" id="childs_name" value="{childs_name}">
                <input type="submit" name="submit" value="Update" class="button small red">
            {/exp:safecracker}      
        {/case}
    {/exp:switchee} 

{/exp:channel:entries}

Here is the form that I want to display if no matches are found.

{exp:safecracker 
            channel="dynamic_activity" 
            return="/admin/story/"
            use_live_url="no"
            error_handling=“inline” 
            preserve_checkboxes=“yes” 
            include_jquery="no" 
            author_id="CURRENT_USER"
            author_only="yes"
        }
            <input type="text" name="title" id="title" value="Dynamic Content for {embed:related_activity_id}">
            <input type="text" name="related_adventure_id" id="related_adventure_id" value="{embed:related_adventure_id}">
            <input type="text" name="related_activity_id" id="related_activity_id" value="{embed:related_activity_id}">
            <input type="text" name="childs_name" id="childs_name" value="Enter the Childs Name">
            <input type="submit" name="submit" value="Submit" class="button small red">
        {/exp:safecracker}

If I use limit="1" then it only displays the first entry if I check if there is no content that matches then I load the form multiple times for each non matched entry. Any ideas/Help is appreciated.

Thanks

UPDATED: I have also tried this ...

{exp:switchee variable = "{related_activity_id}/{related_adventure_id}" parse="inward"}

            {case value="{embed:related_activity_id}/{embed:related_adventure_id}"}
                {exp:safecracker 
                    channel="dynamic_activity" 
                    return="/admin/story/"
                    use_live_url="no"
                    error_handling=“inline” 
                    preserve_checkboxes=“yes” 
                    include_jquery="no" 
                    author_id="CURRENT_USER"
                    entry_id="{entry_id}"
                }
                    <input type="text" name="title" id="title" value="{title}">
                    <input type="text" name="related_adventure_id" id="related_adventure_id" value="{related_adventure_id}">
                    <input type="text" name="related_activity_id" id="related_activity_id" value="{related_activity_id}">
                    <input type="text" name="childs_name" id="childs_name" value="{childs_name}">
                    <input type="submit" name="submit" value="Update" class="button small red">
                {/exp:safecracker}      
            {/case}

            {case default="Yes"}
                {exp:safecracker 
                    channel="dynamic_activity" 
                    return="/admin/story/"
                    use_live_url="no"
                    error_handling=“inline” 
                    preserve_checkboxes=“yes” 
                    include_jquery="no" 
                    author_id="CURRENT_USER"
                    author_only="yes"
                }
                    <input type="text" name="title" id="title" value="Dynamic Content for {embed:related_activity_id}">
                    <input type="text" name="related_adventure_id" id="related_adventure_id" value="{embed:related_adventure_id}">
                    <input type="text" name="related_activity_id" id="related_activity_id" value="{embed:related_activity_id}">
                    <input type="text" name="childs_name" id="childs_name" value="Enter the Childs Name">
                    <input type="submit" name="submit" value="Submit" class="button small red">
                {/exp:safecracker}
            {/case}
    {/exp:switchee} 
0

I would stash the output in a variable so you can then show the form if that variable is empty. Something like this should probably work:

{!--  ============================================  
FETCH CONTENT
================================================== --}

{exp:stash:set name="content" trim="yes" parse_tags="yes" parse_depth="2"}
    {exp:channel:entries channel="dynamic_activity" dynamic="no" author_id="CURRENT_USER"}

      {exp:switchee variable="{related_activity_id}/{related_adventure_id}" parse="inward"} 
        {case value="{embed:related_activity_id}/{embed:related_adventure_id}"}
            {exp:safecracker 
                channel="dynamic_activity" 
                return="/admin/story/"
                use_live_url="no"
                error_handling=“inline” 
                preserve_checkboxes=“yes” 
                include_jquery="no" 
                author_id="CURRENT_USER"
                entry_id="{entry_id}"
            }
                <input type="text" name="title" id="title" value="{title}">
                <input type="text" name="related_adventure_id" id="related_adventure_id" value="{related_adventure_id}">
                <input type="text" name="related_activity_id" id="related_activity_id" value="{related_activity_id}">
                <input type="text" name="childs_name" id="childs_name" value="{childs_name}">
                <input type="submit" name="submit" value="Update" class="button small red">
            {/exp:safecracker}      
        {/case}
      {/exp:switchee} 

   {/exp:channel:entries}
{/exp:stash:set}

{!--  ============================================  
DISPLAY CONTENT
================================================== --}

{if {exp:stash:not_empty name="content"}}
   {exp:stash:get name="content"}
{if:else}
   Fallback content
{/if}
| improve this answer | |
0

Add a case statement

{case default="Yes"}
    Content to show
{/case}
| improve this answer | |
  • I did try that and it returned the matched results as well as a default form for each unmatched channel entry – user1407 May 2 '13 at 22:26
  • Did you try to move that default above the other case? – Brian Peddle May 3 '13 at 0:51
  • Also what if you moved the: {exp:switchee variable="{related_activity_id}/{related_adventure_id}" parse="inward"} on the outside of the {exp:channel} Then add the default case outside of {/exp:channel} – Brian Peddle May 3 '13 at 0:54
  • similar results, I think the issue is determining if there are no entries that match within a channel to only display one form. Right now it displays a form for every entry that does not match. I think I am going to try Stash and see if that works – user1407 May 3 '13 at 9:54
0

I'd recommend in this particular case you might consider using Croxton's equally impressive ifelse add-on in place of switchee, since it seems like the conditionals you are looking for may be a little outside a purely switch case need. You get all the same benefits of early parsing the outer conditional while only parsing the interior of the matching condition, but with the structure of a conventional if:else kind of approach. You may find it suits your purpose more closely here.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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