problems with channel:entries tag within a catchall field
Posted: 09 February 2011 09:44 AM   [ Ignore ]
Wallflower
Rank
Total Posts:  5
Joined  2010-12-05

I’m building a site that sells bags, and using safecracker for the order form. The site has two chanels, bags and custom-orders. I’m using safecracker to post to the custom-orders channel, and in the form is a catchall field that uses an embedded entries tag from the bags channel to populate the field. This works fine for the order form, and the posted entries show up properly in the control panel, but I’m having trouble figuring out how to display the catchall field on the front end. The templates I’m using are below.

The order form (works fine):

{exp:safecracker channel="custom-orders" entry_id="{last_segment}" return="custom-orders/order/ENTRY_ID" }

<fieldset>
<
legend>Choose your bag style</legend>
{embed="custom-orders/.co-bags"}    
</fieldset>
...
<
input type="submit" name="submit" value="Place Order" />
</
fieldset>
{/exp:safecracker} 

The embed:

<ul>
{exp:channel:entries channel="bags" dynamic="no"}
<li class="column-{count}">
    <
label for="co-order[{url_title}]">{title}</label>
    <
input name="co-order[{url_title}]" value="{co-order}{{url_title}}{/co-order}" />
</
li>
{/exp:channel:entries}    
</ul

And here’s the template I’m using to display it on the front-end (not working):

{exp:channel:entries channel="custom-orders" limit="1" }

    {embed
="custom-orders/.co-bags"}
    
...
{/exp:channel:entries} 

And the embed:

<ul>
{exp:channel:entries channel="bags" dynamic="no"}
<li class="column-{count}">
    
{title}{co-order}{{url_title}}{/co-order}
</li>
{/exp:channel:entries}    
</ul

This template displays the contents of the channel entries tag properly, but it doesn’t show the contents of the catchall field. I’m thinking that it isn’t working because I’ve got part of my safecracker code in the embed, but I can’t figure out a way around it. Am I missing something, or is this just not possible (I’m actually sort of surprised that the entry form works)?

Profile
 
 
Posted: 10 February 2011 07:38 AM   [ Ignore ]   [ # 1 ]
Absolute Heartthrob!
Avatar
RankRankRankRankRank
Total Posts:  10369
Joined  2008-09-29
<ul>
{exp:channel:entries channel="bags" dynamic="no"}
<li class="column-{count}">
    <
label for="co-order[{url_title}]">{title}</label>
    <
input name="co-order[{url_title}]" value="{co-order}{{url_title}}{/co-order}" />
</
li>
{/exp:channel:entries}    
</ul

What is output there in the HTML source? Do you have a field called co-order in the custom-orders channel AND in the bags channel? Looking at your code.. that’s what it suggests… which could be where the problem lies.

 Signature 
Profile
 
 
Posted: 10 February 2011 09:01 AM   [ Ignore ]   [ # 2 ]
Wallflower
Rank
Total Posts:  5
Joined  2010-12-05

Here is the output from that embed:

<ul>
    <
li class="column-1">
        <
label for="co-order[small_box_bag]">Small Box Bag</label>
        <
input name="co-order[small_box_bag]" value="" />
    </
li>
    <
li class="column-2">
        <
label for="co-order[large_box_bag_set]">Large Box Bag Set</label>
        <
input name="co-order[large_box_bag_set]" value="" />
    </
li>
    <
li class="column-3">
        <
label for="co-order[teeny_triangle]">Teeny Triangle</label>
        <
input name="co-order[teeny_triangle]" value="" />
    </
li>
</
ul

The co-order field is a safecracker catchall field in the custom-orders channel. There is no co-order field in the bags channel. That’s why I’m surprised that the form works properly; I thought it would choke on the {co-order} tags in the bags channel entries tag.

Profile
 
 
Posted: 10 February 2011 11:15 PM   [ Ignore ]   [ # 3 ]
Absolute Heartthrob!
Avatar
RankRankRankRankRank
Total Posts:  10369
Joined  2008-09-29

If there’s no co-order field in the bags channel… then this is not going to work:

<ul>
{exp:channel:entries channel="bags" dynamic="no"}
<li class="column-{count}">
    
{title}{co-order}{{url_title}}{/co-order}
</li>
{/exp:channel:entries}    
</ul

That code means that you’re pulling co-order data from the bags channel… where it doesn’t exist.

 Signature 
Profile
 
 
Posted: 11 February 2011 12:53 AM   [ Ignore ]   [ # 4 ]
Wallflower
Rank
Total Posts:  5
Joined  2010-12-05

That’s what I thought. But I’m using the bags channel to define the parameters of my catchall field in the custom-orders channel ({co-orders}). Is there some other way that I can output the catchall field’s contents in my template?

Profile
 
 
Posted: 11 February 2011 01:48 AM   [ Ignore ]   [ # 5 ]
Absolute Heartthrob!
Avatar
RankRankRankRankRank
Total Posts:  10369
Joined  2008-09-29

2 Problems. 1. You must pull the data from the custom-orders weblog. 2. You’re trying to generate a dynamic variable: {{url_title}} which won’t work under normal circumstances using standard EE template language. I think for something like this, you’ll need to use PHP on input in an embed to output the dynamic variable so that it can be parse correctly.

MAIN:

<ul>
{exp:channel:entries channel="bags" dynamic="no"}
<li class="column-{count}">
    
{title}{embed="template_group/template_name" url_title="{url_title}"}
</li>
{/exp:channel:entries}    
</ul

EMBED:

<?php $url_title="{embed:url_title}"?>

{exp
:channel:entries channel="custom-orders" limit="1" }
{co
-order}<?php echo "{".$url_title."}";  ?>{/co-order}
{
/exp:channel:entries} 

Due to the vagaries of embed variable parsing… I *think* the embed variable will actually be parsed before the PHP. Weird I know… but I think that’s the ticket.

 Signature 
Profile
 
 
Posted: 11 February 2011 08:35 AM   [ Ignore ]   [ # 6 ]
Wallflower
Rank
Total Posts:  5
Joined  2010-12-05

Having the channel:entries tag in my main template caused a parse error, so I put that code in the main embed, and added a second embed with the php parsed on input.

The php is working, and it is creating the appropriate tag from the {embed:url_title}, but the channel:entries tag in the new embed doesn’t seem to be returning any results.

Profile
 
 
Posted: 11 February 2011 09:41 AM   [ Ignore ]   [ # 7 ]
Absolute Heartthrob!
Avatar
RankRankRankRankRank
Total Posts:  10369
Joined  2008-09-29

Try running that template on its own. Get it to work using standard EE template stuff… then start using it as an embed, and passing the variables in dynamically. At this point… I’d just like to point out that the issue isn’t SafeCracker having a bug… but standard EE template parsing shenanigans. Whatever method you’d usually use to troubleshoot channel entries problems, that’d be the best way to attack this.

 Signature 
Profile
 
 
Posted: 11 February 2011 09:59 AM   [ Ignore ]   [ # 8 ]
Wallflower
Rank
Total Posts:  5
Joined  2010-12-05

I figured it out. I needed to define a status in my entries tag. I actually don’t even need the php. I can just use {{embed:url_title}} and it works fine.

Profile
 
 
Posted: 12 February 2011 04:54 AM   [ Ignore ]   [ # 9 ]
Absolute Heartthrob!
Avatar
RankRankRankRankRank
Total Posts:  10369
Joined  2008-09-29

Gahh… statuses…

/me sighs….

 Signature 
Profile