Published by Mijingo

tips icon image

EE Insider Tips
Sponsored by Mijingo's EE 2 Screencasts

ExpressionEngine mini-howtos created by the EE Insider community.

Structure Module: Category Pages

User's avatar
  • Posted by Hambo
  • July 30, 2009
  • 4 people have found this tip helpful.

To show a weblog listing in a Structure managed template you have to use dynamic=“off”. But this also means that if you use a category filter, the URL will be ignored.

This usually means creating a dedicated category template but this isn’t the ExpressionEngine way right?!

So let’s use embedded variables in the way Paul Burdick intended (I hope!)

Cut out your listing weblog and create a separate template (in an includes template group for example). In this example I will add it to _inc and call it _html_articles.

It will look something like this -

{exp:weblog:entries weblog="articles" orderby="date" dynamic="off" sort="asc"}
<div class="entry">
<
class="date">{entry_date format='%l, %F %d, %Y'}</p>
<
h2 class="title"><a href="{url_title_path="articles/detail"}">{title}</a></h2
            
{categories}
<class="category">Category:<a href="{path="articles/index"}">{category_name}</a></p>
{/categories}
        
<p>{article-summary}</p>

</
div>
{/exp:weblog:entries} 

Now in your index template create some conditionals and some embeds like this -

{if segment_2 == "category"}
{embed
="_inc/_html_articles" dynamic="on"}
{if
:else}
{embed
="_inc/_html_articles" dynamic="off"}
{
/if} 

* Rememeber that you can change the category indicator so change the conditional to match

Going back to your _html_articles embedded template change the dynamic parameter from

dynamic="off" 

to

dynamic="{embed:dynamic}" 

So what we are doing is to check the URL. If there is no category indicator then pass a variable to the embedded template that invokes dynamic=“off” which shows the initial weblog listing.

If the second segment has a category indicator then change dynamic to on which will then allow the URL to control the output.

This should also work with Calendars and maybe even the Gallery module although I haven’t tested these yet.

Hambo05:52 on 07.31.2009

I found out you can also pass the embed variable like this -

{embed="_inc/_html_articles" dynamic="{if segment_2 == "category"}on{if:else}off{/if}"
Paul Burdick06:43 on 07.31.2009

“So let’s use embedded variables in the way Paul Burdick intended”

Obviously, I need to go trademark my name…

You can keep your main template clean by using simple segment conditionals in the embedded template to either created an Assigned Variable or possibly even to se the parameter directly.  No need to do embedded variables at all.

sehart12:15 on 07.31.2009

Having some trouble getting this to work.

Do I need to create a separate template outside of structure to make this work? Or should it work within the Structure URL tree?

sehart12:17 on 07.31.2009

For example, my listing is at say, /bios.

If I turn dynamic=“on”, and goto /bios/category/{category_url_title}, it does not work.

Hambo20:21 on 08.02.2009

@Paul Ah of course. I assume this is because Assigned Variables are parsed before everything else?

@sehart The index template is within structure. The embedded template is not.

gstewart18:43 on 10.30.2009

Is there another code example? I followed the above but it’s not working.

bart08:13 on 02.18.2010

This works when your structure is the same as your template structure.
If your template is called ‘news’ and your structure page is called ‘news’ this does the trick, but when this isn’t the same I think this workaround does not work. Or am I missing something?

Add Your Comment?

You must have an EE Insider account to post comments on Insider Tips. It's fast, easy and hassle-free.

Sign up now (or login).

Search EE Insider Tips
Sponsored By