EE2: embed not displaying properly - expressionengine

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"}

Related

Sending entry data to embedded template

I have a basic ecommerce site which has a products page, in which a full overview of the products is displayed, including thumbnails, brief description, etc. On the same page, and other pages on the site, there is a sidebar which lists the products by title only.
Since the sidebar is reused around the site I want to set this as an embedded template.
With this setup, must I retrieve all the products from the database twice; once in the main Products page, and again in the sidebar? Or is there any way to speed things up on the Products page by retrieving the entries once in the parent template and passing them to the embedded page?
For example:
products parent template:
<html>
{exp:channel:entries channel='products'}
// display full product info
{/exp:channel:entries}
{embed='includes/_products_sidbar' data={entries}} // ^ Can I pass all the data from the above loop to this embedded template?
</html>
embed:
{if data}
// if we already have the data available then use it without having to get it all again from the database
{else:if}
// if not then use another entries loop:
{exp:channel:entries channel='products'}
// display a list of products
{/exp:channel:entries}
{/if}
I think you are better of using a different approach. Have a look at layouts:
https://docs.expressionengine.com/latest/templates/layouts.html
or, if that's not possible, you can use stash https://github.com/croxton/Stash too.
oh yeah, you'll get better help on https://expressionengine.stackexchange.com/

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

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

Related entries in a Safecracker form?

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

Expression Engine: How do I inlude a the correct category url title in the link to an article?

I am working on an EE 1.7.1 site and need to display the two most recent article entries on the home page. The challenge is that I also need to link those entries back to their respective category pages to display properly.
Here is the code I have so far:
{exp:weblog:entries weblog="articles" limit="2"}
<p>{title}</p>
{/exp:weblog:entries}
Here is what I would like to do so that it brings in the corresponding :
{exp:weblog:entries weblog="articles" limit="2"}
{categories}
<p>{title}</p>
{/categories}
{/exp:weblog:entries}
Unfortunately this doesn't work correctly. What is the right way to do this?
Thanks.
ExpressionEngine doesn't natively have a method of including the Category Name as a URL Segment when outputting the Permalink URI, unlike, say, WordPress.
It can be done of course, but will require hacking around the standard EE URL Segments.
If you're even the least bit curious, this was discussed in more detail on the EE Podcast, Episide #10 Behind the Scenes at Playgrounder.
The relevant discussion between Dan Benjamin and Ryan Ireland occurs between 18:45 - 26:20, when Dan details how he developed the unique permalink structure for Playgrounder:
Spoiler Alert: Playgrounder URLs are built using a last segment variable to
lookup the Entry URL Title, while the rest of the preceding URL is the output by
looping thru the entry's categories.
For example, given the following URL:
http://playgrounder.com/stuff/learning/books/sneaky-uses-for-everyday-things
Would translate into EE parlance as:
/index.php/category_url_title/.../url_title
You probably need to add dynamic="off" parameter in exp:weblog:entries tag.
Are you trying to show the latest two entries and their associated categories? Such as:
Entry Title
Posted In: Gifts, Pets, Toys
Some Other Entry Title
Posted In: Toys, Toddlers
If that's what you're trying to do, the following code will output the above:
{exp:weblog:entries weblog="news" limit="2"}
<p>
{title}<br />
{categories limit="1"}
{if category_id != ""}Posted In: {/if}
{/categories}
{categories backspace="2"}{category_name}, {/categories}
</p>
{/exp:weblog:entries}

Resources