Please forgive if this is a dumb question - I am a Panels 2 newbie.

So . . . I am trying to do a taxonomy override with a path similar to: /path/[term-name]

(Using term ID in the path does not fit our needs, as well.)

I have created view panes that accept the [term-name] as an argument.

I add these to a panel page I have created that uses [term-name] as an argument itself.

I then add the view panes via content tab - feeding the argument to them using either "Send arguments" or "Additional Arguments" (using "@0").

Both work fine.

The only problem is that we do NOT wish to spaces in our URL (either regular or URL encoded %20).

We would rather use dashes.

This is allowed when creating the View itself (just check "transform spaces to dashes in url"), but they do not work when that same view added as a pane to a panel page.

(Does this make sense?)

Anyways, I have come to the conclusion that:

1.) I am doing something wrong - and there is an easy way to do this (perhaps using contexts?? which I don't quit understand yet)

2.) There is no way to do this in Panels 2 - in which case I would like to request this as a feature request for Panels 3.

3.) Only way to do this is a hack. (I am open to suggestions.)

I also would love to know from more experienced "Pannelers" whether I should wait for Panels 3 to mature before even messing with any of this. (Is there going to be an upgrade path from Panels 2 for D6 to Panels 3? Is Panels 3 alpha 1 just as stable as Panels 2 alpha 3? Where the heck should I start?)

Comments

miiimooo’s picture

subscribing

miiimooo’s picture

Version: 6.x-2.0-alpha3 » 6.x-3.0-alpha4

The workaround I have found looks like this - my Page has a path "campaign":
I added this to settings.php

function custom_url_rewrite_inbound(&$result, $path, $path_language) {
/** url rewriting for dashes **/
  if (strpos($path, "campaign/") === 0) {
    $result = str_replace("_","-", str_replace("-"," ", $path));
  }
}
function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
  if (strpos($path, "campaign/") === 0) {
    $path = strtolower(str_replace(" ","-", str_replace("-","_", $original_path)));
  }
}

This rewrites dashes to underscores and spaces to dashes - assuming that underscores are not being used in term names..

merlinofchaos’s picture

The custom URL rewrite is a good one. The taxonomy term argument needs some more intelligence like the Views one has. Right now it's kind of dumb. Patches accepted.

friolator’s picture

Version: 6.x-3.0-alpha4 » 6.x-3.0

I'm assuming we're seeing the same issue here, in panels 3.0. So is this still an open issue within panels? we have a really odd situation that seems to be related to this:

"places/%region" (taxonomy terms as argument to custom page)
"places/%region/%state" (taxonomy terms as arguments to custom page)
"places/%region/%state/%node-title" (panels system node/view override w/url alias to match the previous two urls)

In the case where the state name has two words ("New York", "New Hampshire", "North Carolina", etc), the argument only works if we leave the space in the term in the URL. If we put in a dash, the page comes up with a 404. In the case of one-word states ("Maine" "Massachusetts," "Wisconsin"), the argument works perfectly.

In the views preview, dashes work fine. I've even tried adding in taxonomy term synonyms (such as "new-hampshire") but that's not doing it. we'd use term ids instead of names, but it's nicer to have the url be human-readable, and hackable, so people can delete the %node-title and see all the places in the state, for instance.

Is there an easy workaround to this? we're closing in on launch and just noticed this problem - it's a bit of an edge case for us, but we'd rather not have spaces in our URLs if we can help it.

merlinofchaos’s picture

Right now, Panels doesn't have the smarts that Views does in terms of translating arguments for spaces to dashes. There are two workaround:

1) use a string context and pass it directly to Views. This means you can't use the context for Panels specific stuff.

2) Write an argument plugin based on the existing one that will do translations for you. Some of the needed code is already in Views, though it's a little abstracted so may be difficult to utilize.

friolator’s picture

Since we don't really need the full taxonomy context in this situation, passing it as a string works just fine.

thanks!

merlinofchaos’s picture

Status: Active » Fixed

Marking fixed since you seem to have a workaround.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

pwilson’s picture

miiimooo's workaround worked for me (kudos miiimooo), but I do think it'd be nice to have this built into Panels. I have no Earthly idea how difficult it might be, but if it isn't monumentally difficult I would love to see this in a future release. Keep up the phenomenal work =D

Thanks,
Patrick

dinomight’s picture

Status: Closed (fixed) » Active

The post in #2 seems like a good workaround to me, but I'm having trouble understanding how to implement it. I first tried inserting this snippet into my default.settings.php file, but that did nothing for me. I then tried it in settings.php as miiimooo did, but that didn't work either. Whenever I try to include the dashes I need in my url, I get a page not found error.

My url is "2010-totfootball/schools/," so I replaced the word campaign with schools. I also tried replacing it with 2010-totfootball/schools/.

I considered just changing my taxonomy to have the dashes built into the term names, but that won't work since I need to use the normally formatted (with spaces) term name as a title in my panes.

I'm definitely confused at the moment.

theo38’s picture

I second the above post - where should this code be placed?

cedarm’s picture

Project: Panels » Chaos Tool Suite (ctools)
Version: 6.x-3.0 » 6.x-1.7
Component: Panel pages » Code
Category: support » feature
StatusFileSize
new2.36 KB

Today we created our /taxonomy/term/%term override and ran into this same thing. We needed the %term context to pass "term-name" to a panel (a views content pane) rather than "Term Name" or the term id. A patch to ctools provides this via context conversions of %term to term name with spaces transformed to dashes, the reverse of views. This way we can setup the views Argument using the "Transform dashes in URL to spaces in term name arguments" checkbox. It works nicely.

BTW we're only actually using the 'name_dashed' conversion in terms.inc. All of it needs testing...

I think this makes sense to have as part of ctools since it matches views functionality, but does this actually need to be implemented here? Can another module implement a context plugin that will do this? (pathauto?...)

merlinofchaos’s picture

Status: Active » Needs review
ericclaeren’s picture

The ctools patch in #12 worked perfectly for me! Nice work, could this patch be included in a new ctools release?

merlinofchaos’s picture

Status: Needs review » Fixed

Committed to all branches.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

kclarkson’s picture

Status: Closed (fixed) » Active

I have searched through all the forums and cannot find an easy resolution to this.

Can anybody provide a step by step to allow the panels argument to show urls with hyphens?

cedarm’s picture

There's a context token called %term:name_dashed that corresponds to argument from context "Term name, lowercased and spaces converted to dashes" in views. Is that what you need? What are you trying to do with the argument?

kclarkson’s picture

@cedarm,

Thank you for getting back to me so quickly and I apologize ahead of time if I am mixing things up.

I am using panels and views to show a content type of faculty Award and a content type of Award Recipients. So both content types are sharing the same taxonomy terms so I would like to show them both on one page.

I have the panels arguments working for terms that have one word, but when they have spaces it says argument is not available. I tried entering hypens but it only works when adding %20 in for the spaces of the url.

So I have done the following:

1. Created a default view with some fields and an Argument of Taxonomy Term
2. Added a "content pane", display,
2a Added basic validation
2b checked the transfer spaces to dashes
2c. In the Pane Settings under the Argument Input I selected "from Panel Argument" and first.

3. Created a Panel Page
3a. Added argument, used taxonomy term ID, selected "term name" and limited to my vocabulary of "awards and funding"
3b Created a custom path of. %term I also tried %1

PS. I understand you gave me a context token that would use dashes. I added your context token to the url and it did not work. If you could explain a little bit more about the context token I should be able to figure it out.

cedarm’s picture

Version: 6.x-1.7 » 6.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new2 KB

kclarkson needs this same feature in the term arguments plugin, for his step 3a. Here's a stab at it. This may be used with or without the corresponding views transform.

kclarkson’s picture

bump

calefilm’s picture

I followed all of Kclarkson's steps.. Did this patch help you?

If I apply this patch will this resolve my issue? I'm currently using 6.x-1.8--I didn't know if it was worth using Dev.

In my case, a user is coming from another page, having clicked a link called "Western Digital" to view the Western Digital Review page. Each Brand's review page has a corresponding taxonomy term, i.e. "Western Digital". reviews/%brand

My example: reviews/%brand where "Western Digital" is the brand. I'm trying to tell my panel page to transform spaces to dashes but have tried kclarkson's steps to no avail.

There's a context token called %term:name_dashed"

I'm confused by this... I don't see this option.. and if I add it to my URL as Kclarkson did it doesn't work as my pane argument tab stops working.

Very confused how to set this all up.

cedarm’s picture

You don't need to use dev. Just apply the patch from #20.

There are two things you must get right.
- panels must be able to convert the page path into a context (using a panels argument)
- you must pass the correct type of argument from panels to views

These are two different arguments. You do not need to use the same type for both. For example
reviews/%brand (term dashed) -> term context -> term id -> views
or
reviews/%brand (term dashed) -> term context -> term name (dashed) -> views

are equally valid, but views must be expecting whatever argument you send it. Likewise, %brand could be a term id itself:
reviews/%brand (term id) -> term context -> term id -> views
or
reviews/%brand (term id) -> term context -> term name (dashed) -> views

Decide for yourself which makes sense for your site, then configure BOTH appropriately.

kclarkson’s picture

Can we get this patch tested and committed?

I have tough time adding patches and I update my modules frequently.

calefilm’s picture

Thanks Cedarm,

I really appreciate your assistance. I did set the panel argument correctly and it works although I don't know if my further issue is related.

So now, if a user types in mysite.com/reviews/western-digital the panel page works.

But I have a separate page of all listed brands being reviewed:

Sony
Western-Digital
Panasonic

Within this view, I've added a field, node title: Brand Label. Within this field, I have an "Output this field as a link": reviews/[field_brand_label_value]
(keep in mind, all "brand labels" are node titles which were referenced from the Taxonomy Terms list upon creating the node)

When I go to this view, I see:

Sony
Western Digital
Panasonic.

I click the Western Digital link, and the URL reads: mysite.com/reviews/western%20digital



UPDATE: This seems to be a bigger issue than I thought. I found a couple open issues regarding this problem: http://drupal.org/node/514078#comment-2031486 I did try Path Redirect module. This doesn't quite fix my problem as I have hundreds of links to fix--it would not be feasible.

cedarm’s picture

@calefilm - you got it; separate issue. Personally I'd probably theme the views field and do the replace in a theme or preprocess function.

kclarkson’s picture

Does calefilm's usage count as the patch being tested?

calefilm’s picture

I've themed the views before but to "do the replace in a theme or preprocess function" is beyond my scope entirely." Appreciate your responses, cedarm. Luck

webavant’s picture

After reading your comment (#20), it's not totally clear what you have changed with this patch, but I do notice that you added the "term name (dashed)" argument handler, which was exactly what I needed. I tested the patch in #20 and have not noticed any errors. It did exactly what I needed and made my day. Thanks.

cedarm’s picture

@webavant that's exactly what the patch in #20 adds, another option in the argument handler.

summit’s picture

Hi, Is this patch committed already?
Thanks for your reply in advance.
greetings, Martijn

mstrelan’s picture

Is any of this available in Drupal 7 version? It doesn't seem like it.

robertom’s picture

subscribe for future reading (interested on Drupal 7 version)

mstrelan’s picture

In addition to my comment in #32 here is what I am trying to achieve

I want to set up eat-and-drink/search/%dining_type to point 301 redirect to eat-and-drink/search?dining_type=%dining_type:tid but ideally the first instance of %dining_type should be %dining_type:name_dashed however that doesn't seem to work.

mstrelan’s picture

Sometimes coming back to something the next day reveals that there was a much better approach. For #34 instead I created a variant for taxonomy/term/%taxonomy_term which performed my 301 redirect, and I setup pathauto to alias my dining type vocabulary terms to eat-and-drink/search/[term:name] which handles the hyphens for me.

Still, I think what I was initially attempting should work.

cedarm’s picture

That patch in #12 was committed; the patch in #20 has not yet and is what you need. Do you see %dining_type:name_dashed in the page context?

mstrelan’s picture

Do you see %dining_type:name_dashed in the page context?

No

cedarm’s picture

So that's why it didn't work. Have you applied the patch in #20? I tried it for your use case and it works for me.

Edit: I take that back. #20 is for handling term name dashed arguments.

rlmumford’s picture

Is there a Drupal 7 version of this patch? Or are they the same?

Josh Benner’s picture

Status: Needs review » Reviewed & tested by the community

#20 works for me.

pelicani’s picture

#20 works for me.
thanks!

Jason Dean’s picture

Also interested to know whether #20 works in D7?

  • merlinofchaos committed 59c8828 on 8.x-2.x
    #358953 by cedarm: Allow term context to return lowercase, spaces to...

  • merlinofchaos committed 59c8828 on 8.x-3.x
    #358953 by cedarm: Allow term context to return lowercase, spaces to...
japerry’s picture

Status: Reviewed & tested by the community » Fixed

This was fixed by Merlinofchaos

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.