Thread tagged as: Question

Getting URL from category item

Hello guys, i am currently making a small presentation website for a client and i got some trouble with perch categories. I have few pages with colors in it and each of them contains about 50 different colors. One of the pages is named "standard colors". Additional i have a "color search" page where i can filter all my colors by color tone. So far it works as i wanted to. If i click on red tones, i get all colors associated to the category red.

But heres my problem: I want to link each color i receive in my color search to its original page.

My first attempt was to use

PerchSystem::set_var('var_url', perch_page_url([], true));

but this doesn't work. The original color shows the url but i cant pass it to the color search. Maybe you know a better way to achieve this.

Heres the code of my two templates:

color template

        <span class="m-color" style='background-color:#<perch:content id="colorcode" type="text" label="Color Value" textile="true" replace="#|" help="Hex Value with or without hash prefix (e.g. #ff0000 / ff0000)" />;'></span>
        <perch:content id="colorname" type="text" label="Color Name" textile="true" title="true" />

<perch:categories id="color" label="Category" set="Colors" required="true"/>
<perch:content id="var_url" type="hidden" suppress="false"/>

color search template

    <a href='<perch:content id="var_url" type="hidden" />'>
        <span class="m-color" style='background-color:#<perch:content id="colorcode"/>;'></span>
        <perch:content id="colorname"/>
        <p>url: <perch:content id="var_url"/></p>

I appreciate your help and thank you in advance! Greetings, Bastian

Bastian Silbereis

Bastian Silbereis 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't really understand. Where is the colour's URL defined?

Thats the problem. I want to link to the page where the color is integrated, without defining the link manually. (because there could be up to 100 colors on one page it would be pretty awkward to write the URL to every single color)

Drew McLellan

Drew McLellan 2638 points
Perch Support

Does the category path or slug form part of the link?

No, i just want to link to the page where the color is located.

standard-colors.php (contains about 80 different colors)

by-color.php?cat=red (shows 3 red tones from "standard-colors.php" and a few more from other pages)

Therefore one of the 3 red tones should link to "standard-colors.php"

Sorry for my confusing explanation. :-/

Drew McLellan

Drew McLellan 2638 points
Perch Support

So something like this?

by-color.php?cat=<perch:category id="catSlug" />

Nope, im looking for the link to standard-colors.php.

I have multiple pages on my site (page1.php, page2.php, page3.php, ...). Each page stands for a paint set and each of these sets contains multiple different paints. So maybe "page1.php" has two red paints, 13 green paints and 5 blue paints. In my "by-color.php" i want to let the user search all paints by a specific tone. (red, green, blue) If the user clicks on red he gets two red paints from "page1.php" and a few more from the others pages. (thats the part that works fine so far) Lets say the user chooses the first red paint and he wants to buy the related paint set. Therefore i need a link from "by-color.php" to the paint set "page1.php"

And exactly this link is what i am looking for.

I hope this helps.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't think I have a solution for that if your page name can't be determined from the data available.

Normally you'd name the page in a way that can be deduced, so you might want to look at the architecture of your site.