2

I am looking for a way to add some logic to a view's (styled as Jump Menu) selection options. The View's UI allows me to "output this field as a link" but I need to do something like this:

if (current_url == 'something') {
  link_here();
}
else {
  link_there();
}

Basically all I want to do is to figure out where to theme (a template or other files) the following part:

<option value="6ee3dbb066bb38cb7fb90872a6f0144e::/Cakes/AllCakes/[tid]">Chocolate</option> 
1

In the Views UI, when you edit the View, open up the "Advanced" options. The penultimate option (one up from the bottom) is "Theme: Information." Here's an example:

If you click on "Information" you'll be given a list of template suggestions like this one:

enter image description here

And if you then click on one of the output types (i.e. "Display output," "Style output," etc), you'll be shown the boilerplate code for a template that should be named with one of the names to the right of the style type, which you can cut and paste into a file you save with the appropriate name. Like so:

enter image description here

Once you've got the template name to use, and some code to go in it, create your template in your theme directory and modify to rewrite the links as you require. I happened to choose the "Display output" template as my example, but you'll most likely want to use the "Field Content" template/associated template name.

Note that this is an information-only option in Views - it won't create the template for you. You'll have to do that yourself. You can cut'n'paste from the boilerplate to get started.

I hope that helps...

1
  • I know how to theme Views in general, I didn't need a tutorial on that; what I need is for the Jump Menu style specifically, which template (if there is one) produces the <option> tags and their perspective contents.
    – magtak
    Feb 22 '12 at 8:11
1

After "manually" producing the link by rewriting fields, I was able to theme that field and complete my task.

Instead of Using the views' "Link the output of this field" functionality, I created an extra "Custom Text" field in the view in which I created the links manually ("AllCakes/[tid]").

By theming this field with views' template files, I was able to add an if statement based on the current URL

<?php
  if (arg(1) == 'AllCakesList') {
$output = str_replace("/AllCakes/", "/AllCakesList/", $output);
  }
?>
<?php print $output; ?>

Thus I successfully linked to where I wanted.

3
  • If you can describe in detail how you did, that would make this an answer; differently, this answer is not helping any future reader.
    – apaderno
    Feb 22 '12 at 14:02
  • Done, hope it's better now
    – magtak
    Feb 22 '12 at 14:11
  • Yeah, still waiting on the timer :)
    – magtak
    Feb 22 '12 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.