• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

Drupal 5.X - block visible based on field and URL

I have created a custom content type where I will enter information that needs to appear in a block in the sidebar on specific pages.  It will contain information about specific brands that our company carries, and needs to show up when the title or URL of the page contains that brand's name.

so what I did was make a field in the custom content called "Brand" and I want to make the content show up in a block when the title or URL contain that string.

Can anyone point me in the right direction past that.  To demonstrate how lost I am - right now that block shows all of the content of the entire site.
0
kellybelly
Asked:
kellybelly
  • 5
  • 3
1 Solution
 
oliverpoldenCommented:
This should be quite easy.  You just need to use PHP to break the path into an array and then search the array and title for the brand.

You may need to do some fiddling with the elements of the array and the brand name to make sure they match. e.g. if your path says /content/my-brand-name, and your Brand name is My Brand Name, then you would need to convert the brand name to lowercase and convert spaces to hyphens
<?php
$path = drupal_get_path_alias($_GET[q]); //get URL alias
$path = explode(/, $path) // Split path into an array
$path[] = drupal_get_title(); // Add the title to the array
 
return in_array('[YOUR BRAND NAME]', $path);
 
?>

Open in new window

0
 
oliverpoldenCommented:
Some weird characters have come out, they're all single quotes
0
 
kellybellyAuthor Commented:
is that code for the arguments in the view, or the block visibility?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
oliverpoldenCommented:
In the block visibility.  You could modify and put that in the arguments in the view.  Depends what you want to do.  If you want it to appear for just one brand then it's easier to put it in the visibility however you may still have the overhead of the view generating the block on every page even if it doesn't display, not sure about that one.  If you want it to appear different for different brands then yes you would need to add it to the argument which is actually an example I took some code from but it's for Drupal 6, not sure about 5:  http://www.ridgesolutions.ie/index.php/2009/01/19/passing-an-argument-to-a-block-view-in-drupal-6/

My comment is wrong by the way!  
0
 
kellybellyAuthor Commented:
the content type has a field in it called 'field_brand'
if I put the code above in and replaced [YOUR BRAND NAME] with $field_brand should that make it show the quick facts box only when the brand name is present in the URL?
0
 
oliverpoldenCommented:
I've got an idea but I'm not sure if you can do it in views 1.  What you could do is create a content type that contains your quick facts.  You could create a taxonomy of brand names that links your node with your quick facts.  Then you can create a relationship between your node and your quick facts based on brand.  An alternative would be to store your quick facts in your node buy creating pre defined values in your content type which you could then select.  You could create a template for this content type which would allow you to position your quick facts, or you might find you can do all you want with CSS.
0
 
kellybellyAuthor Commented:
these all sound like good options - I will have to spend a little time with taxonomy.  What you are suggesting with that was something that had occurred to me also.
It seems like this is probably something that people do all the time - having certain type of content that shows up in a block and the actual node changes based on the page selected.  How would it be handled normally?  (I am trying to make sure that I am not making this more complicated than it has to be.)
0
 
oliverpoldenCommented:
Yeah it's easy to make things complicated.  Now I've got a better idea of what you're trying to do I would probably do it this way:

Set up your brand taxonomy.  You can then use the path_auto module to make your nodes have a path of something like /brand-name/node-title.  i.e. /[taxonomy-name]/[node-title].  Then you can create a view that generates a block of quick facts and use the trick to get the first part of the address i.e. the taxonomy to use as an argument.

I haven't quite got the time to go into specifics but the path_auto module will help you out anyway. http://drupal.org/project/pathauto
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now