ExpressionEngine: Embed and filter - expressionengine

I got "Data/.List" file with content:
<!-- SubList 1 -->
{embed="Element/.ListThumb" e_id="1" e_cat="cat1" e_name="A"}
{embed="Element/.ListThumb" e_id="2" e_cat="cat2" e_name="B"}
{embed="Element/.ListThumb" e_id="3" e_cat="cat3" e_name="C"}
{embed="Element/.ListThumb" e_id="4" e_cat="cat1|cat3" e_name="D"}
<!-- SubList 2 -->
{embed="Element/.ListThumb" e_id="11" e_cat="cat2" e_name="E"}
{embed="Element/.ListThumb" e_id="12" e_cat="cat3" e_name="F"}
{embed="Element/.ListThumb" e_id="13" e_cat="cat1|cat3" e_name="G"}
{embed="Element/.ListThumb" e_id="14" e_cat="cat1|cat2" e_name="H"}
and in index I want to embed and render filtered elements:
{exp:channel:entries channel="categories"}
<section>
{name}
{embed="Data/.List" e_cat="{id}"}
</section>
{/exp:channel:entries}
And I want to achieve:
Category1:
A, D, G, H
Category2:
B, E, H
Category3:
C, D, F, G
I cannot change Data/.List
So how can I achieve this result or with which query should i look for solution (tried: "ee conditional embed", "static embed", "filter embed")
I'm using channel to easily add new categories with "order" field
Channel Category is using id field (eg. "cat1")
Data/.List is like "row file" for me,
so I will write simple script to parse it to file like this
{if embed:cat == "cat1"}
{embed="Element/.ListThumb" e_id="1" e_cat="cat1" e_name="A"}
{embed="Element/.ListThumb" e_id="4" e_cat="cat1|cat3" e_name="D"}
{embed="Element/.ListThumb" e_id="13" e_cat="cat1|cat3" e_name="G"}
...
{/if}
{if embed:cat == "cat2"}
{embed="Element/.ListThumb" e_id="2" e_cat="cat2" e_name="B"}
...

Assuming {id} from index is e_id specified in Data/.List...
{exp:channel:entries channel="categories"}
<section>
{name}
{if id == 1}
{embed="Element/.ListThumb" e_id="{id}" e_cat="cat{id}" e_name="A"}
{if:elseif id == 2}
{embed="Element/.ListThumb" e_id="{id}" e_cat="cat{id}" e_name="B"}
{if:elseif id == 3}
{embed="Element/.ListThumb" e_id="{id}" e_cat="cat{id}" e_name="C"}
{if:elseif id == 4}
{embed="Element/.ListThumb" e_id="{id}" e_cat="cat1|cat3" e_name="D"}
{if:elseif id == 11}
{embed="Element/.ListThumb" e_id="{id}" e_cat="cat2" e_name="E"}
{if:elseif id == 12}
{embed="Core/.ListThumb" e_id="{id}" e_cat="cat3" e_name="F"}
{if:elseif id == 13}
{embed="Core/.ListThumb" e_id="{id}" e_cat="cat1|cat3" e_name="G"}
{if:elseif id == 14}
{embed="Core/.ListThumb" e_id="{id}" e_cat="cat1|cat2" e_name="H"}
{/if}
</section>
{/exp:channel:entries}
Thus bypassing the template you mentioned can't be changed because it's impossible to deliver what you want without avoid it or changing it.
If this answer is still way off your requirement, we need more information as to what is the end objective and data structure as I think the current approach is the problem, as there are too many fundamental questions with it...
Why not use relationships?
Why have you got a channel called "categories" instead of using native categories?
You have a channel called categories, but then you're hard coding the e_cat in the template - surely this value should be part of the categories data?
Why can't you change Data/.List? This is the template that's causing all the issues!
Is the intention to use different template groups with Element and Core, or is that a mistake?

Related

How do you check if a file description is empty or not in Expressionengine 2?

I am using Expressionengine 2. I would like to check to see if the file description is not empty so that if there is any content it will be used instead of the entry title in the alt tag.
Currently I have the code below which brings in the entry title but I can't work out how I get the logic in place to check the existence of descriptive text for the file (image):
<img class="aClass" src="{work_detail_extra_image_01}"
alt="
{if work_detail_extra_image_01:description != ""}
{work_detail_extra_image_01}{description}{/work_detail_extra_image_01}
{if:else}
{title}
{/if}
"
border="0" />
Thanks for taking a look
Try removing != "" so that line becomes:
{if work_detail_extra_image_01:description}.
It'll see if it exists or not.
I'd try to display the description there first without conditionals to make sure they aren't your problem.
Try this:
<img class="aClass" src="{work_detail_extra_image_01}"
alt="{work_detail_extra_image_01}
{if work_detail_extra_image_01:description != ""}
{work_detail_extra_image_01:description}
{if:else}
{title}
{/if}
{/work_detail_extra_image_01}
"
border="0" />

Expression Engine, filter relationship's entry by category id

I have the channel Market and Family. Both have the same expressionengine's category group.
I want to print out all the entries of the channel Market with the category XY, and for each market I want to print ONLY the first family entry of category XY related to it.
In my solution, seems that the category parameter inside the relationship field "market-families" doesn't work. here is the code:
{exp:channel:entries channel="Market" category="{segment_2_category_id}" orderby="title" sort="asc"}
{if "{url_title}" == "{segment_3}"}
<li class="active">
{if:else}
<li>
{/if}
{market-families orderby="title" sort="asc" category="{segment_2_category_id}" limit="1"}
{title}
{/market-families}
</li>
{/exp:channel:entries}
Legend:
{segment_2_category_id} -> plugin to get the category id from a segment.
market-families -> Multiple relationship field inside channel Market
Thank you for any help :)
Have you tried manually entering the category id in the parameter instead of using the plugin just to verify that it's not the plugin?
I couldn't find any specific reference to the relationship field being able to use the category parameter in ExpressionEngine's documentation: http://ellislab.com/expressionengine/user-guide/modules/channel/relationships.html

How can I filter search results by category in ExpressionEngine 1.6.8

I have inherited search results template in an EE 1.6.8 install and would like to filter the results by category. This is possible to a point but the paged results are incomplete i.e display an inconsistent no. of results. I believe this is because the template is doing n+1 queries (bad enough in the first place) in a nested query via a custom localisation module (However, if I remove that then my content is not localised)
{exp:search:search_results disable="member_data|trackbacks" orderby"date" paginate="bottom" limit="10" show_expired="no" show_future_entries="no" }
{count}
{exp:localisation:local_query local_sql_url_title="content-from-url-title" page_url_title="{url_title}" }
{categories}
{if category_group ==1}
{if category_name == "Videos"}
<p>
...
</p>
{if:elseif category_name == "audio"}
<p>
...
{if:elseif category_name == "Images"}
...
{if:elseif weblog_short_name == "gpress-releases" }
...
{if:elseif weblog_short_name == "articles" }
...
{if:elseif weblog_short_name == "press-kits" }
...
{/if}
{/if}
{/categories}
{/exp:localisation:local_query }
{/exp:search:search_results}
Does anyone know how I can filter search results by category when an article might be assigned to more than one category (in another group)? I need to display slightly different content e.g. a different icon based on the category name.
Upgrading to EE 2.x is not an option at this time.
Why not just upload your category icon as the category image for each category? Your template will be much cleaner and simpler:
{exp:search:search_results disable="member_data|trackbacks" orderby"date" paginate="bottom" limit="10" show_expired="no" show_future_entries="no"}
{count}
{exp:localisation:local_query local_sql_url_title="content-from-url-title" page_url_title="{url_title}" }
{categories}<img src="{category_image}" alt="{category_name}" class="category-icon" />{/categories}
{/exp:localisation:local_query }
{/exp:search:search_results}`

ExpressionEngine - PHP in template, Print something if entry has certain field value?

I have a template that is used for entries. The entries have a field that will always have 1 of 2 values. Can I write some PHP to show something different depending on the field value?
Ive tried the following but it gives me a PHP error:
<?php if($my_field == 'value1') { ?>
<h3>Value 1</h3>
<?php } else { ?>
<h3>Value 2</h3>
<?php } ?>
Thanks
You don't have to use PHP.
{if my_field == 'foo'}
Value 1
{if:else}
Value 2
{/if}
If you're planning on doing any EE tag processing within those conditionals, you shouldn't use the if:else syntax, as with it, the content between the conditionals will always be parsed, but just not displayed, which needlessly uses server resources and increases load time.
So in that case, use simple conditionals instead:
{if my_field == 'foo'}
Value 1
{/if}
{if my_field == 'bar'}
Value 2
{/if}
See: http://expressionengine.com/user_guide/templates/globals/conditionals.html
You can use ExpressionEngine's Conditional Global Variables to display your content, without having to use PHP in your templates.
Rewriting your example using native ExpressionEngine's Simple Conditional tags would result in the following:
{exp:channel:entries channel="channel_name" dynamic="off"}
{if "my_field" == "value1"}
Value 1
{/if}
{if "my_field" == "value2"}
Value 2
{/if}
{/exp:channel:entries}
You can use simple or complex conditionals anywhere in your templates, with the former being less resource expensive, but ExpressionEngine's Parse Order (PDF, 32 KB) may affect how they're evaluated and replaced.
In most cases, you'll need to ensure your custom fields and conditionals are within the {exp:channel:entries} tag loop for the values to be properly output and tested when the page is being built.

"no_entries" conditional logic

Is this possible to do the following in ExpressionEngine:
(code taken from here)
IF THERE ARE RELATED ENTRIES SHOW THIS: (important to see the header)
HEADING : Related Entries:
Entry 1
Entry 2
Entry 3
ELSE (SHOW NOTHING)
...
DONE
Code:
{related_entries id="performers"}
{if no_related_entries}
<h2>No Entries</h2> {/if}
<h2>{title}</h2> {body}
{/related_entries}
How do I hide the header? Because the only way to check if there are related entries is to actually start the {related_entries} LOOP.
Any hints? I don't want to hack into PHP for this.
{related_entries id="performers"}
{if title != ""}
<h2>{title}</h2>
{/if}
{body}
{/related_entries}
This should do it, no need for no_related_entries, since you do not plan on doing anything if there is nothing.
Since you have header tags around your title, I imagine you want to avoid printing out header tags when there isn't any related entries.
so if title is not empty, display, if it is, then it won't, so you'll avoid <h2></h2>
don't worry about putting a conditional around the body tag, it will just not display anything if it is blank, but if you put an html tag around it like you did the title, then you would do the same as you do w/ the title conditional.
This ought to do the trick
{related_entries id="performers"}
{if no_related_entries}
<h2>No Entries</h2>
{if:else}
<h2>{title}</h2> {body}
{/if}
{/related_entries}
Sam "SammyTheSnake" Penny

Resources