Forum

Thread tagged as: Question, Forum

Displaying repeater categories content

Hello,

I'm trying to add classes to <span> tags so that I can style them based on the category I've assigned to it. I was able to get the classes added without the repeater tag, but not in the way that I want. When I add the repeater, no classes show up.

List page

<h2 class="entry-cat"><perch:categories id="interest" label="Interest" set="interests" limit="1"><span class="<perch:categories id="interestsclasses" label="Interests Classes" set="interests-classes"><perch:category id="catTitle" type="text" /></perch:categories>"> <perch:category id="catSlug" type="text" /></span> </perch:categories></h2>

Detail page (w/o repeater)

<perch:categories id="interestsclasses" label="Interests Classes" set="interests-classes">
    <perch:category id="catTitle" type="text" />
</perch:categories>

Since some entries have more than one class, I get this with the above code: <span class="cat1 cat2">Info</span>

but I want: <span class="cat1">Info</span> <span class="cat2">Info</span>, or something similar where two separate span tags are created around Info. So then I tried adding the repeater as below:

Detail page (w/ repeater)

<perch:repeater id="catClass" label="Class">
<perch:categories id="interestsclasses" label="Interests Classes" set="interests-classes">
    <perch:category id="catTitle" type="text" />
</perch:categories>
</perch:repeater>

and I also tried the scope-parent code to see if that did anything, but I get the same result.

List page (w/ repeater + .parent)

<h2 class="entry-cat"><perch:categories id="interest" label="Interest" set="interests" limit="1"><span class="<perch:categories id="parent.interestsclasses" label="Interests Classes" set="interests-classes"><perch:category id="parent.catTitle" type="text" /></perch:categories>"> <perch:category id="catSlug" type="text" /></span> </perch:categories></h2>

Detail page (w/ repeater + scope-parent)

<perch:repeater id="catClass" label="Class" scope-parent="true">
<perch:categories id="interestsclasses" label="Interests Classes" set="interests-classes">
    <perch:category id="catTitle" type="text" />
</perch:categories>
</perch:repeater>

Both repeater tests give me: <span class>Info</span>

Diagnostics Report

Perch: 3.0.10, PHP: 5.6.31, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (3.0.10), assets (3.0.10), categories (3.0.10), perch_blog (5.5.1), perch_gallery (2.8.9)
App runtimes: <?php $apps_list = array( 'perch_gallery', 'perch_blog' ); ?>
PERCH_LOGINPATH: /cms
PERCH_PATH: /home3/itsblamc/public_html/foxxwork/cms
PERCH_CORE: /home3/itsblamc/public_html/foxxwork/cms/core
PERCH_RESFILEPATH: /home3/itsblamc/public_html/foxxwork/cms/resources
Image manipulation: GD Imagick
PHP limits: Max upload 64M, Max POST 64M, Memory: 256M, Total max file upload: 64M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
DOCUMENT_ROOT: /home3/itsblamc/public_html/foxxwork
HTTP_HOST: foxxwork.com
REQUEST_URI: /cms/core/settings/diagnostics/
SCRIPT_NAME: /cms/core/settings/diagnostics/index.php
Ariana Farquharson

Ariana Farquharson 0 points

  • 3 years ago

First thing I always do is add <perch:showall /> to the template and see if the tag you're trying to use exists in the output.

If it does, it will show your the namespace and the key.

Duncan Revell

Duncan Revell 78 points
Registered Developer

I don't think you need a repeater at all - see if something like this works:

<h2 class="entry-cat">
<perch:categories id="interestsclasses" set="interests-classes">
<span class="<perch:category id="catTitle" />">
<perch:categories id="interest" set="interests" limit="1"><perch:category id="catSlug" /></perch:categories>
</span>
</perch:categories>
</h2>

Robert,

Thanks. Without the repeater, <perch:showall /> shows the interestsclasses tag with an array that corresponds to the assigned category (I assume that's what the numbers in the array refer to).

With the repeater, I don't see interestsclasses (category ID), but I do see catClass (the repeater ID).

I'm not quite sure what that means, though, in terms of what I need to change in my code.

Duncan,

Almost works. I did get two separate span classes with the appropriate tags applied, but it still lumps the assigned categories together:

<span class="bus">
creativebusiness
</span>
<span class="cre">
creativebusiness
</span>

It should be like this:

<span class="bus">
business
</span>
<span class="cre">
creative
</span>

Ok, still messing with it. Here's another close trial, although it might be too much...

<h2 class="entry-cat">
<perch:categories id="interestsclasses" set="interests-classes">
<div>
<perch:categories id="interest" set="interests" limit="1"><span class="<perch:category id="catSlug" />"><perch:category id="catSlug" /></span></perch:categories>
</div>
</perch:categories>
</h2>

which gives me:

<div>
<span class="creative">creative</span>
<span class="business"business</span>
</div>
<div>
<span class="creative">creative</span>
<span class="business"business</span>
</div>

It's not the same classes that I intended ("cre" and "bus"), but it would still work fine if I can manage to get just one instance of the div.

EDIT: "creative" and "business" would NOT work fine, because I forgot that those are attached to something else. I need for them to be "cre" and "bus."

Removing the div tag leaves me with four span classes, where "creative" and "business" still show up twice each.

Duncan Revell

Duncan Revell 78 points
Registered Developer

Ah, sorry - I saw the limit="1" and wrongfully assumed you were limiting id="interest" to one entry only (that would be max="1"). My bad.

I'll look again and see if there's a way to get what you're after...

Duncan Revell

Duncan Revell 78 points
Registered Developer

Are your class names always the first 3 characters of the category?

If so, try:

<h2 class="entry-cat"> 
<perch:categories id="interest" set="interests" limit="1">
<span class="<perch:category id="catSlug" format="C:3" />">  // just the first 3 chars of catSlug
<perch:category id="catSlug" />
</span> 
</perch:categories> 
</h2>

You won't then need the interest-classes at all.

Duncan,

To answer your question: Yes, and that solution works perfectly. Thanks so much for your help!

Nice call Duncan.... :)