Showing content based on URL alias

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
boaz_r's picture

Hi,

Am I missing something or what? : I'm looking for a way to make panels 3 show content (node) based on the url alias - to match the requested URL with the URL alias of the node.
Can this be done with panels 3 ? (This is D6 with the latest CCK, panels, ctools modules to date).

Thanks!

Comments

Context

Halffull's picture

Use context to do what you're asking, in order to use it you need to select "allow the use of context" before hand.

can you tell how *exactly* to achieve that?

boaz_r's picture

I know about context but AFAIK there is no context on URL-alias, only on node ID.

Boaz
PHP therapist

Panels can't do it. Hallfull

bennos's picture

Panels can't do it.

Hallfull means the drupal module context. http://drupal.org/project/context

Think there was a features request in the panels issue queue, but this is not implemented. Also in the content issue queue was discussed about an interaction with panels.

i'll have a look

boaz_r's picture

i'll have a look at context module.

thanks!

Boaz
PHP therapist

what we did

boaz_r's picture

hi all,

i was contacted and asked how we resolved this. we did more or less this:
created our own block using hook_block. This block, on its "view" operation searched in the DB a published node that some "Clean url" field in it matches the one that is currently used for 'this' request. When found, it load it and rendered it.
we did not use the url alias field due to limitation that i cannot fully remember. It was either some limitation or requirement on that field that wasn't exactly like what the built in (path module) url alias field gives.
on the panels, all you had to do is to add content to a variant, and get that block (panels integrates with blocks).
cest tout, i guess.

we used similar mechanisms elsewhere as well. panels integration to block module is the key feature we used to implement our own solution.

Boaz
PHP therapist

CTools Access Plugin

mlconnor's picture

I believe that the way to do this is to develop a CTools access plugin. The argument for the plugin would take a path, exactly the way it's done for block visibility, and then provide access only if the url_alias destination (dst) matches up. This would give designers the ability to develop a Panel for each section of the site. For example...

http://somecompany.com/about_us/press_room/press_releases

We could then apply a panel for the press releases section by specifying...

/about_us/press_room/press_releases/*

Another way to handle this that already works out of the box with Panels is to use taxonomy. This is all well and good but I don't want the content authors to have to have to tag each press release just so the proper Panels template appears.

Any better ideas on how to do this? If not, I think I'll just code up the plugin. I'm a bit worried about performance though.

Curious question: if you have

jcisio's picture

Curious question: if you have two alias, article/1 and press_room/pr/1 for one url node/1, how can you show different urls? The url('node/1') returns only one. Is it done manually?

got it

mlconnor's picture

Finally figured this out. I was able to create a ctools plugin that controls access via the node path from the context. I also used the drupal_match_path function so that it behaves like blocks. You can basically say that you want a certain panel variant to respond to all files at specific URLs or even wildcards.

about_us/press_room
about_us/press_room/press_releases/*
about_us/exec_bios/*

Panels does give you the ability to intercept content at specific URLs using the Page Panel. my problem is that i don't want to pass a node id or other parameter on the URL. I wanted to use PathAuto to generate nice URLs using the menu path and page title. Panels is then called upon to control the template in certain sections of the site. You can of course also combine this with taxonomy and content type to say something like...

Use this panel variant for all nodes that...
1. Are of type computer_hardware
2. Tagged with the term 'storage'
3. In the section '/products/white_label/*'

You get the idea... The CTools plugins are confusing at first but once you get the hang of it it's pretty straight forward.

Can anyone tell me if there is an easier way to do this? If not, I'll probably build a module to hold this plugin.

Post more detail in your example?

scottprive's picture

boaz_r - could you post more example detail? Is the content provided by Node or by Views? Are the aliases "convenience" or SEO paths, or would you like it if the "alias" could replace/eliminate toe /node/NID pathing?

I have done the above without any code at all. However I am not sure how much of the problem I solved applies to your case, and since my solution was EXTREMELY convoluted (term/TID %context passes to a view, which serves as arguments to select documents of 'site_structure' type, where the arguments basically ask for the [unenforced] one document which would contain this argument as a value. In other words, each page gets 'tagged' with it's menu name and the view pulls that up.).

So I have this working off 1 or 2 Panels pages:
/company
/company/news/*
/company/about_us
/company/technology

I'll stop here because I'm not yet sure how relevant my solution is. :-)

I'm very interested in the

achton's picture

I'm very interested in the details here, providing I understand the premise of the problem:

  • You have friendly URLs for content generated by Pathauto, e.g. /article/nice-title-here
  • You do not want to have to rewrite the friendly URLs to, say, /article/473/nice-title-here in order to activate your Panel page
  • Your panel page grabs the argument via /article/%node and should translate this into a node ID

Is that correctly understood? If so, how can I achieve this without code?

Cheers,
Achton


See drupal.org/u/achton for profile.