bread crumbs for views drupal 7 - drupal-7

Am working with views and am wondering if there is a way to get the view to update the breadcrumb trail. When on my first view called homme the breadcrumbs are not updated it still just says "home >" as if it is still on the homepage. When I click a post the breadcrumbs update to "Home › Blogs › admin's blog › ". I need it to say Home > Homme > Name of Article, basically what you would expect when going to a blog site or post.
Can I get the view to act like a blog?

One option is to try overriding the themeable output generated by the default breadcrumb function.
Assuming you've created your own theme - create a file called template.php at the root of your theme. Create a function named YOURTHEME_breadcrumb, where YOURTHEME is the name of the theme. The HTML returned by this function will be the breadcrumb. Modify the return values as necessary here to get what you want. Consider using Drupal's menu functions to build a more satisfactory breadcrumb.
Check the comments of this API article for more detail: http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_breadcrumb/7

Adding this to your template.php file should work with d7 sites:
function theme_breadcrumb($breadcrumb)
{
if (substr($_GET['q'], 0, 13) == 'news/category') {
$breadcrumb[] = l('News', 'news/');
}
if (count($breadcrumb) > 1) {
if ($breadcrumb) {
return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) ."</div>\n";
}
}
}

Related

how can I load a joomla module as a link?

this is my problem...
I have some of images and links that I want to load different joomla modules when user click on them.
mean each hyperlink can load another module|position
thanks all
In case that you just want to call a module's content from a url the following answer will help you.
If you just want to show / hide a module in the same page you could use something similar to my previous answer: Joomla 3 Show different modules on same position depending on toggler
Joomla provides the functionality to call a specific file of the active template by adding the tmpl=FILENAME key/value to the url's query string.
All built-in templates have a component.php file if user wants to load the template with the component only. You could check the following link for more details: Adding print pop-up functionality to a component.
You could do something similar to only show the modules that you want to load.
You could copy the component.php to a new file (I have used custom.php) and added the following php code in the <body> ... </body> part.
<?php
$jinput = JFactory::getApplication()->input;
$selectedPosition = $jinput->getString("position", "");
$selectedModule = $jinput->getString("module", "");
$selectedModuleTitle = $jinput->getString("title");
if($selectedPosition !== "") {
$modules = JModuleHelper::getModules($selectedPosition);
foreach ($modules as $module) {
echo JModuleHelper::renderModule($module);
}
} elseif ($selectedModule !== "") {
$module = JModuleHelper::getModule($selectedModule, $selectedModuleTitle);
echo JModuleHelper::renderModule($module);
}
?>
So with a similar way as loadposition / loadmodule works you could call the new template file using:
index.php?tmpl=custom&position=MODULE_POSITION
or
index.php?tmpl=custom&module=MODULE_TYPE
or
index.php?tmpl=custom&module=MODULE_TYPE&title=MODULE_TITLE
Optionally if you want to load the module with a specific style, you could pass it to the second paramter of the renderModule method like:
echo JModuleHelper::renderModule($module, array("style" => "xhtml"));
Hope this helps

Add a custom head title to a filtered view page in Drupal

I have a site that filters the blogs by specific expeditions.
Currently, when I click on the blog related to that specific expedition it displays the head title (in browser window) as "| mysite". So all the filtered views have the same head title.
I would like to add a custom head title for each filtered view.
So, for example, I would like the blogs that have do with Expedition 1 to have a filtered view with the head title "Expedition 1 blogs | Mysite".
Does anyone have any suggestions?
I suggest you do this :
for Views 3:
If you have a view and you want to be able to programmatically change the title of, you can do it by implementing hook_views_pre_render in your custom module:
<?php
/**
* Implements hook_views_pre_view().
*/
function MODULENAME_views_pre_render($view) {
if ($view->name == 'my_view_name') {
if ($view->current_display == 'my_display_name') {
$view->set_title('my new title');
}
}
}
?>
I hope it helps.
This question may be related to this one where the following solution was given:
In template.php:
function YOUR_THEME_preprocess_page(&$vars){
// You can test if you're in your specific views of course
$path = $_GET['q'];
if (strpos($path,'YOUR_PATH_STRING') !== false) {
drupal_set_title('YOUR_TITLE');
}
}
I also saw the reference to the Page Title module that could suit you.
You can set views page title programmatically by using below hook in modules.
function MODULE_NAME_views_pre_view(&$view, &$display_id, &$args) {
if($view->name == 'VIEW_MACHINE_NAME'){
$view->display[$view->current_display]->display_options["title"] =
$view->display[$view->current_display]->handler->options["title"] =
$view->human_name .' - '.$_GET['field_video_by_event_value'];
}
}

Getting current page in CakePHP pagination

On one of my webpage, I show a list of customer details with default pagination [Paginator helper]. Each customer row has a corresponding 'edit' button which when clicked shows a DIV populated with that customer information. [This DIV has textboxes etc. where I can change customer info] After re-entering/modifying customer details, when I click on "Save" button, 2 ajax calls are made..
First one to save the edited record
The second one Updates the customer Listing on the same page with modified information
My problem : If I am on page 3 and edit one customer record, the 2nd ajax call refreshes the list but does not go to the page 3. It starts from page 1.
Please help.
You can get your current page here:
<?php echo $this->Paginator->counter(array(
'format' => ('{:page}')
)); ?>
This is part of the solution. :)
You can get your current page here:
$this->request->params['named']['page']
Did you try to use the link from Paginator? It maintains the page # to the controller.
Something like
// same parameters as $this->Html->link
<?php echo $this->Paginator->link( ... ) ?>
Check also the reference documentation for the Paginator Helper
I use jquery / javascript to store the page on a cookie and then read it from the controller.
// -------------------------------------------------------------------------
// on action click remember current page
$('td.actions').click( function( event )
{
var page = $('li.active a').html();
var name = window.location.href.split('-').join('_').split('/').pop();
$.cookie.raw = true;
$.cookie( 'CakeCookie[' + name + '_page]', page, { expires: 365, path: '/' } );
});

How to keep a clean browser history in a backbone.js app?

My backbone.js has three views:
List of categories
List of items in category
Form for individual item
I'm using backbone.js router to navigate between these views. The user flows in the app go 1<-->2, 2<-->3 and 3 --> 1. The user can navigate back and forth using browser back and forward buttons, which is wanted behavior. Deep linking to any item works also.
The problem is that I want to keep the history clean. Here's an example usage flow:
User opens list of categories. History: "Category list" (correct)
User select "My category". History: "My category" < "Category list" (correct)
User select "My item". History: "My item" < "My category" < "Category list" (correct)
User fills form and saves, is redirected to "Category list". History: "Category list" < "My item" < "My category" < "Category list" ( should be just "Category list" )
Another example:
User opens url of "My category"
User presses home button. History: "Category list" < "My category", should be "Category list"
Any ideas on how to implement this in a clean way?
There is no way to implement the first example that you provided. You cannot implement the first example because there is no way to "delete" the browser history using Javascript.
There is no way to clear the session history or to disable the back/forward navigation from unprivileged code. The closest available solution is the location.replace() method, which replaces the current item of the session history with the provided URL.
- https://developer.mozilla.org/en/DOM/window.history
At best you can prevent the current page from being added to the browser history by using window.location.replace or window.history.replaceState. Backbone.js provides a convenient way of doing this by calling router.navigate(fragment, [options]) on your router object and specifying {replace: true} in the options.
Instead of relying on different routes to determine which view to display, I would try instead writing a master view which could handle showing/hiding the specific views.
EDIT
Ok, entering hacky territory...
Since it seems that the "Category List" page is the page where history should be "reset", the solution I have posted attempts to solve both use cases you have mentioned. The code keeps track of a historyState variable, which represents when the "category-list" page is visitied as well as the other pages visited after it.
// in your application init...
$(function(){
window.historyState = -1;
router = new Backbone.Router({
routes: {
"category-list": category-list,
"category": category,
"item": item
}
category-list: function(){
historyState = 0;
},
category: function(){
if(historyState >= 0)
historyState++;
},
item: function(){
if(historyState >= 0)
historyState++;
}
});
});
If historyState is -1 - we have not yet visited the "category-list" page.
If historyState is 0 - we are currently on the "category-list" page.
If historyState is greater 0 - number of pages visited since viewed "category-list" page.
Now anytime a link is used to navigate to the "category-list" page, make sure it calls the following method to handle the appropriate navigation.
function routeToCategoryList(){
if( historyState > 0 ){
// 'category-list' already exists in our history route to that page.
window.history.go((historyState * -1));
} else {
// otherwise, don't store an entry for the current page we are on.
router.navigate("/category-list", {trigger: true, replace: true});
}
}
If the 'category-list' page has already been visited go back in history the appropriate number of entries (this unfortunately keeps the other pages in the history, so you can still go forward to them). Otherwise if the 'category-list' page hasn't been visited yet navigate to it and be sure not to add the current page to the history.
There is no way to delete history from backbone history, you can re-route the navigation by adding some logic by getting current fragment
or you can use history.js (Works on most of the browser)
while https://developer.mozilla.org/en/DOM/window.history is only for Mozila firefox so this does not work for android app

Drupal 7: Multiple pages for one node

We list events on our Drupal 7 site, but we'd like our users to be able to register for these events via a simple form. We're using Pathauto to generate URL aliases for events using the following pattern: events/[node:title]. We would like to have another page with the alias events/register/[node:title] which would present the registration form. We would also like to use tpl.php files for creating the templates, like we do for the rest of the site.
Any ideas on how we might accomplish this? Thanks.
You can try the Signup module. It's still in development, but over 7000 sites are using it:
I would put a register button on the event/ page via the node.tpl.php file. If all your nodes are not registerable, then you can check the node by getting the $nid with $node->nid and run a db_query on the url_alias table to see if current node qualifies.
<?php
$nid = $node->nid;
$result = db_query('SELECT alias FROM {url_alias} WHERE source = :source,
array(':source' => 'node/'.$nid));
foreach ($result as $r) {
$alias = $r->alias;
}
if (strpos($alias, 'events')) {
?> <input... or <button...
Have your register button redirect to events/register/$node->title page and make sure you pass the node. There's a few different ways to go from here. If you have questions about this part open another thread.

Resources