Related entries in a Safecracker form? - expressionengine

I'm trying to create a Safecracker form in ExpressionEngine to create a recipe. I have a recipe channel, which can have many ingredients from an ingredients channel (using the multi-relationship add-on from devot:ee). However, I'm having trouble listing the ingredients within my form. This is my mark-up:
{exp:safecracker channel='recipes' datepicker='no' id='add-recipe-form' include_jquery='no' return='recipes/view/ENTRY_ID' safecracker_head='no'}
{related_entries id='ingredients'}
{title}
{/related_entries}
{/exp:safecracker}
The problem is, the actual EE tags are just getting output on my web page.
I figure I'm doing something fundamentally wrong, so could someone point me in the right direction? Thanks.

This is called "variable collision" - you're nesting entries which use the same variable/tag names as those used by the parent tag (in this case, {title}), and due to how EE's parse order works, the parent tag is winning every time.
The solution is to put your above code into another template, and embed that template within your Safecracker form. Embeds are run at the very end of template processing, after all of the other EE tags are parsed, so you won't run into the same collision.

Derek is right, you need to embed your related entries. I've got this working on my Toronto EE meetup site with this code.
Simplified Template code:
{exp:safecracker channel="gta-attendee"}
<div class="form_row" style="display:none;">
<label class="small">Choose Meetup to Attend:<span class="required">*</span></label>
{embed="includes/_playa_select" selected="{attendee-event:child_ids}" }
</div>
{/exp:safecracker}
embedded code:
{exp:channel:entries dynamic="no" channel="gta-meetup" limit="1"}
<input value="{entry_id}" name="attendee-event[selections][]" type="hidden">
{/exp:channel:entries}
In the code I'm using the Playa Module, but the principle is the same.
Hope this helps
Sean

Related

How Can i add the customized section to home page in broadleaf

Hi I am new to broadleaf and i want to add the customized products to home page of broadleaf like the home page will load two cateogries of products at at time for example the home will want to load top sale products and hot sauces.
Please help me to Solve the issue.
Thanks in Advance
First off, i am not that experienced with broadleaf either, but my background has made it pretty easy for me to wrap my head around ( i think), and there are a quite a few different ways to do this and it really depends on how you ultimately like to maintain the lists, and your experience level.
As you have said you are just getting started, i'll give you what i think is the most simple way to do this.
First, assuming you are working from a recent version of the demo site. In this case, the home page is actually just a category with a custom template. If you look in the Admin app at the "Home" category and select the "Products" tab, you will see a list of the 4 Hot Sauces that are displayed on the home page in the Demo store.
The important thing to note here is that it is specifically not the "Hot Sauces" category, it is a specific subset that is selected in the admin app, giving you control of the not only the items displayed but the number of items displayed.
If you have seen the code in the homepage html template, you will see something like:
<div class="row">
<h3 class="text-center">
The Heat Clinic's Top Selling Sauces
</h3>
<th:block th:if="${products}" id="products" class="group" th:each="product : ${products}" th:object="${product}" >
<div class="col-sm-6 col-md-3" th:if="${product.isActive()}"
th:include="catalog/partials/productListItem">
</div>
</th:block>
</div>
This is the code in the demo site that is displaying the list of hot sauces on the home page. The CategoryController retrieved ths list of products for the category and put them in the Model.
Now, the absoloute easiest way to add a second list of products to the home page is use the same technique. In Admin look at the "Marketing" tab, you will see the same list of 4 products in the "Featured Products" section. As far as I am aware this is not actually being used in the new versions of the demo site. Note that there is also the upsell and xsell product lists, but for this purpose i am just going to use the Featured Products list. I suggest you change these to some other products now just so you can see the changes to the home page are pulling the correct list later.
In homepage.html insert something like the following code (it's similar to the code you looked at above):
<div class="row">
<h3 class="text-center">Top Selling Products</h3>
<th:block th:if="${category?.featuredProducts}" id="featuredProducts" class="group" th:each="featuredProduct : ${category.featuredProducts}">
<div class="col-sm-6 col-md-3" th:with="product=${featuredProduct.product}" th:object="${featuredProduct.product}"
th:include="catalog/partials/productListItem">
</div>
</th:block>
</div>
And your done.
This is certainly not the only way, or even the best way, unless your definition of best is "It takes 5 minutes and 6 lines of HTML".
At some point, depending on how your requirements pan out, you may end up creating a specific HomepageController, this approach should still work in that case, without customising the admin interface, as long as the data is still put in the model by the controller.
FYI: The homepage template is located at site/src/main/resources/webTemplates/layout/homepage.html

Expression Engine- Show HTML within entries loop even if no results

New to Expression Engine. I have the following code:
{exp:channel:entries channel="blogposts" orderby="date" url_title="{segment_3}" limit="1"}
<div id="cat_head_section">
<div id="cat_title">
<div id="lower_bubble_heading" class="cat_title"><h5>{title}</h5></div>
</div>
</div>
<div id="category_main">
{if no_results}
<h2>Sorry, the post you were looking for either does not exist or has been deleted.</h2>
{/if}
{url_title}
</div>
{/exp:channel:entries}
When there are no results returned, I don't get any of the HTML returned (other than the heading), which is vital to the structure of the page. How do I solve this?
Thanks.
This answer assumes that the entry call you are making here is the main one on the page. If this call is really just for a sidebar or something then this answer may not apply.
Couple of things...
If you are building urls like EE "expects" you to you shouldn't have to specify which url segment to look for the url title. The 'url_title' parameter is generally useful when you are doing something that EE does not expect, such loading a specific entry other than the one that appears in the last segment.
If you are limiting your result to one entry, there's no need to specify an order.
Maybe the reason you think you need the 'url_title=' parameter is because you haven't taken a good look at 'require_entry='.
So we are down to this:
{exp:channel:entries channel="blogposts" limit="1" require_entry="yes"}
Now on to your question:
Think about why and how someone would end up asking for a page that you can't find.
Did the entry get deleted? Did someone retweet a mal-formed URL?
A. You may say these requests really call out for 404 response.
Serving a true 404 instead of a valid page with a "Sorry..." message ensures that the bad page will not be indexed by search engines...
To handle this you want EE's redirect tag.
{if no_results}
{redirect="404"}
{/if}
You'll want to have a genuinely helpful 404 page if you do this.
B. Alternatively you may say that when an entry can't be found you already have in mind a 'next best place' to sent the visitor -- better than your site's 404 page.
So if your visitor is looking for a blog entry that doesn't exist (say: /blog/entry/bad_page) the best place to send them would be to your blog index page (say: /blog). If you care about search ranking, then to the extent that the inbound link that is breaking had some SEO value, a 301 redirect here will help to confer that SEO value on to the page to which you are redirecting.
{if no_results}
{redirect='blog/' status_code="301"}
{/if}
The only thing that will show up if there are no results is what's in between the {if no_results} "if" statement. If you want more HTML in there, you just have to add it in there (which looks like you are duplicating it but you won't be because only one or the other will show up - results or no results).
Alternately, if you'd rather not duplicate the code you might choose to save yout HTML as a separate embedded template, and then pass the appropriate values to it as variable parameters. If no results, assign apologies to your variable values.
See http://ellislab.com/expressionengine/user-guide/templates/embedding.html

Access Categories for each entry of a specific channel in ExpressionEngine

So, I am still trying to figure out how to use expression engine and I want to create a list of all of the entries in a channel, which includes the corresponding categories. I can create the list as follows:
{exp:channel:entries channel="custom_channel"}
<div style = "display:block;padding:10px;border-bottom:1px solid #999999;">
<span>Title: {title}</span><br>
<span>Date published: {entry_date format="%m/%d/%y"}</span><br>
<span>Access: {access}</span><br>
<span>Type: {type}</span><br>
{!--Here is where I am trying to access the corresponding
categories for each of the entries--}
</div>
{paginate}
<p>Page {current_page} of {total_pages} pages {pagination_links}</p>
{/paginate}
{/exp:channel:entries}
So, what this does currently is it goes through the entries and creates the html as defined for each entry. I've tried to include {categories} and other related tags but have not been successful. I have looked online and have not been able to find anything related. Is it possible to access the corresponding categories for each entry? If so, how? Any help is appreciated. Thanks.
Yes, you can use the categories variable pair. Incidentally, if you're looking to tap into the ExpressionEngine community, post your questions to expressionengine.stackexchange.com

Expression Engine entry_id Parse

Hey Everyone I am having a huge problem :
I have this Line :
{exp:entries:ids_assigned_to_me tag="idont" channel="proiecte" field="clienti"}
Which outputs me some entry ids
and i can put it There at the entry_id:
{exp:channel:entries channel="proiecte" entry_id=" HERE " }
{content}
{/exp:channel:entries}
I tryied and search for hours over forums and stuff, but variable, snippets and embeding and stuff doesen't seemed to work out. Any Ideas ? about Inward Parse or something ?
Also tried php but didn't worked out :((
You're using the entries add-on and by the looks of it you're using the single tag method. It's not clear from the documentation, but I think as you're specifying a single tag, it's outputting the IDs, but if you use it as a tag pair (as other examples in the documentation show) and this piece of documentation hints at: "If no entries are assigned the logged in member, the no_results conditional is returned.".
So first try
{exp:entries:ids_assigned_to_me tag="idont" channel="proiecte" field="clienti"}
{content}
{/exp:entries:ids_assigned_to_me}
...all by itself without any {exp:channel:entries} tags. No idea what "tag" parameter is doing in there.
If that doesn't work and that method doesn't support a tag pair, then you'll need to do as an embed across 2 templates:
1st template:
{embed=template-group/second-template entry_ids="{exp:entries:ids_assigned_to_me tag="idont" channel="proiecte" field="clienti"}"}
2nd template:
{exp:channel:entries channel="proiecte" entry_id="{embed:entry_ids}"}
{content}
{/exp:channel:entries}

EE2: embed not displaying properly

I've got a website with two channels, news and products.
Products are displayed using an embedded channel entries tag pair called marketing. The news articles are displayed using a regular channel entries tag pair.
When the user clicks on a news article, the website navigates to a new page (news/view) containing the contents of just the news article in question. The template also includes the embedded template containing the products tag pair. This is where the problem occurs: the only published item that displays is the news article. None of the products display on the news article template.
The homepage and 'news/view' mock-up:
{exp:channel:entries channel="news"}
{title}
<some markup>
{body}
{/exp:channel:entries}
{embed="includes/marketing"}
The marketing embedded template looks something like:
<some dividing markup>
{exp:channel:entries channel="products"}
<list markup>
{product_image}
{product_description}
</list markup>
{/exp:channel:entries}
</some dividing markup>
Since the homepage and the 'news/view' template are essentially the same, I have no idea why the products are displaying on the homepage and not the 'news/view' page.
I'm not entirely sure but try adding dynamic="no" to your channel:entries loop. This seems to resolve 99% of my EE problems :)
{exp:channel:entries channel="products" dynamic="no"}

Resources