Forum

Thread tagged as: Question, Configuration, Blog

Perch blog category conditional

I'm currently using this in one of my blog templates in order to pull out the catTitle.

<perch:categories id="categories" set="news">
                <perch:if id="catTitle" match="eq" value="Athlete Spotlight">
                    <div class="athlete-spot"><span><perch:category id="catTitle" /></span></div>
                </perch:if>
            </perch:categories>

What I also want to do (because I am pulling out two categories of news), is have a slightly different html structure and I'd like to ensure the blog excerpt doesn't get output for posts belonging to the category of articles. I tried:

<perch:categories id="categories" set="news">
            <perch:if id="catTitle" match="neq" value="Athlete Spotlight">
            <div class="news-excerpt">
                <perch:blog id="excerpt" type="textarea" textile="true" chars="240" append="..." />
            </div>
            </perch:if>
        </perch:categories>

Then realized that doesn't work as I'm trying to access the blog namespace within categories. What options are there for this type of thing, would I need to somehow ascertain the post category in my page and pass that into the template? Or could it be done in the template alone?

Mathew Doidge

Mathew Doidge 2 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Does excerpt appear in the parent scope?

It does indeed. With that thought I wrote:

<perch:categories id="categories" set="news" scope-parent="true">
            <perch:if id="catTitle" match="eq" value="Articles">
            <div class="news-excerpt">
                <perch:category id="blog.excerpt" type="textarea" textile="true" chars="240" append="..." />
            </div>
            </perch:if>
        </perch:categories>

Although this doesn't work, if I showall inside of the categories I can see parent.excerpt. I assuming I am trying to access the excerpt incorrectly inside the template

Ok scrap that, I assumed I needed to map the parent scope to the variable, i.e blog.excerpt - I was wrong. Got it working:

<perch:categories id="categories" set="news" scope-parent="true">
            <perch:if id="catTitle" match="eq" value="Articles">
            <div class="news-excerpt">
                <perch:category id="parent.excerpt" type="textarea" textile="true" chars="240" append="..." />
            </div>
            </perch:if>
        </perch:categories>

Thanks Drew <3