Add a custom head title to a filtered view page in Drupal - drupal-7

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'];
}
}

Related

Undefined Values in Kendo Dropdownlist

I am using Telerik's dropdownlist in my MVC application View. I am facing two problems:
1) When I run my application, I find every value of kendo dropdownlist is "Undefined".
This is the code for my View:
#model IEnumerable<EulenMgrKendoUIMvcApplication.Dominio.Tablas.DelegacionProductoUsuario>
#(Html.Kendo().DropDownListFor(d=>d)
.Name("IdDelegacionProductoDrpDwn").HtmlAttributes(new { #style = "font-size:12px" })
.DataTextField("IdDelegacionProducto")
.DataValueField("IdDelegacionProducto")
**.BindTo((System.Collections.IEnumerable)ViewData["IdDelegacionProducto"]))**
This is my controller, where I populate the dropdownlist:
public class DelegacionProductoUsuarioController : Controller
public ViewResult List()
{
IEnumerable<DelegacionProductoUsuario> delegaciones = DelegacionProductoUsuario.GetAll();
**PopulateDelegacionProducto();**
return View(delegaciones);
}
private void PopulateDelegacionProducto()
{
List<Int64> IdDelegacionProductoList = new List<Int64>();
foreach( DelegacionProductoUsuario d in DelegacionProductoUsuario.GetAll()){
IdDelegacionProductoList.Add(d.IdDelegacionProducto);
}
ViewData["IdDelegacionProducto"] =IdDelegacionProductoList ;
}
}
>I am debugging the application and the controller is passing to the view the proper values,so I don't understand why it doesn't show them.
2) Second problem: I insert this Dropdownlist in one of the columns of a kendo grid with no success.
In it's place it appears a common label. Here is the code for my Grid, I mark in Bold the column where I try to show my dropdownList:
#(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns=>
{
columns.Bound(d => d.BorradoLogico).Title("Borrado logico");
columns.Bound(d => d.FTick).Title("Ftick");
**columns.Bound(d => d.IdDelegacionProducto).Title("IdDelegacionProducto").EditorTemplateName("IdDelegacionProductoDrpDwn");**
columns.Bound(d => d.IdUsuario).Title("IdUsuario");
})
How does that 'DelegacionProductoUsuario' class look like? Does it have property named 'IdDelegacionProducto' ? It looks like you have not set the dataValueField correctly.
As for the second question, where did you put that EditorTemplate (is it in the Shared/EditorTemplate or in a EditorTemplates folder? More info about editor template can be found here.
Dear Petur: thanks a lot for answering. On regard to your answer:
My class DelegacionProductoUsuario does have a property called IdDelegacionProducto. On regard to your question "where I place the EditorTemplate" , I don't understand what you mean, I place it in the view that Lists all of my DelegacionProductoUsuario . Please keep on helping me. Thanks a lot Petur.

Add microdata to a Drupal site

Is there a way to add microdata to a Drupal 7 site by editing the field.tpl files? My site is built using panels and views so http://drupal.org/project/microdata isn't working. Is there another way to go about adding microdata by hard coding?
Thanks.
The best way to add microdata is by editing the field.tpl files and then checking - use file templates on views. For panels I used the module http://drupal.org/project/panels_extra_styles to add coding around the pane.
I managed to override the page template file and wrap my panel in a code.
The code I used was
template.php:
function ThemeName_preprocess_page(&$vars) {
// if this is a panel page, add template suggestions
if($panel_page = page_manager_get_current_page()) {
// add a generic suggestion for all panel pages
$variables['theme_hook_suggestions'][] = 'page__panel';
// add the panel page machine name to the template suggestions
$variables['theme_hook_suggestions'][] = 'page__' . $panel_page['name'];
$object = $panel_page['contexts']['argument_entity_id:node_1'];
$result_array = get_object_vars($object);
$value = $result_array['restrictions']['type']['0'];
if($panel_page['name'] == 'node_view' AND $value == 'product' ) {
$vars['theme_hook_suggestions'][] = 'page__node_view_product';
}
if($panel_page['name'] == 'node_view' AND $value == 'artist' ) {
$vars['theme_hook_suggestions'][] = 'page__node_view_artist';
}
and I created a files under ThemeName/templates
page--node_view_artist.tpl.php and
page--node_view_product.tpl.php
I hope this helps someone, it took me a long time to figure it out!

How to go to first page after(before) sorting in extJs grid

I have extJs 4.1 grid with paging. For this grid applied remoteSort(maybe remoting style of sorting doesn't matter) behaviour. After sort click(click on header) I wanna go to first page. How can I achive this? Maybe exists presort callback in what I can cancel loading data and forward loading to first page with store.loadPage(1)?
P.S. Sorry for english.
This code is part of the FiltersFeature.js file.
Take a look at how when to specify (local: false) it goes to first page automagically ;)
reload : function () {
var me = this,
store = me.view.getStore();
if (me.local) {
store.clearFilter(true);
store.filterBy(me.getRecordFilter());
store.sort();
} else {
me.deferredUpdate.cancel();
if (store.buffered) {
store.pageMap.clear();
}
store.loadPage(1);
}
}
What you have to do is configure the feature with local: false.

bread crumbs for views 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";
}
}
}

Filtering data using ajax observefield

I ve tried to implemented filtering data (list base on selected category) using dropdown with observefield and ajax pagination. I use session to remember selected category in order to keep pagination.
Here is my code (Cakephp 1.2)
In view :
echo $form->select('Category.id', $categories, null, array('id' => 'categories'),'Filter by Categories')
echo $ajax->observeField('categories' ,array('url' =>'update_category','update' => 'collectionDiv'));
In Controller:
if(!empty($this->data['Category']['id']))
{
$cat_id=$this->data['Category']['id'];
$filters=array('Collection.category_id' => $cat_id);
$this->set('collections', $this->paginate('Collection', $filters));
$this->Session->write($this->name.'.$cat_id', $category_id);
}
else
{
$cat_id=$this->Session->read($this->name.'.cat_id');
$filters=array('Collection.category_id' => $cat_id);
$this->set('collections', $this->paginate('Collection'));
}
The filter work as I wanted but the problem is when I select empty value('Filter by Category) it still remember last category session so I can't back to the default list (All record list without filter).
I've tried to make some condition but still not success. Is there another way? Please I appreciate your help. thank
hermawan
Perhaps I don't understand the question, but it looks to me like it might be worth changing:
else
{
$cat_id=$this->Session->read($this->name.'.cat_id');
$filters=array('Collection.category_id' => $cat_id);
$this->set('collections', $this->paginate('Collection'));
}
to:
else
{
$this->set('collections', $this->paginate('Collection',array()));
}
In effect your code appears to be doing this anyway. Check what the URL is at the top of the browser window after it has returned. Does it still contain pagination directives from the previous query?
You might want to review http://book.cakephp.org/view/167/AJAX-Pagination and make sure you've 'ticked all the boxes'.
I got it, It work as I hope now. I my self explain the condition and solution.
When I select category from combobox, then it render the page the code is :
If ($this->data['Category']['id']) {
$cat_id=$this->data['Category']['id'];
$this->Session->write($this->name.'.category_id', $category_id);
// I will use this session next when I click page number
$filters=array('Collection.art_type_id' => $category_id);
$this->set('collections', $this->paginate('Collection', $filters));
}else{
//if clik page number, next or whatever, $this->data['Category']['id'] will empty so
// use session to remember the category so the page will display next page or prev
// page with the proper category, But the problem is, when I set category fillter to
// "All Category" it will dislpay last category taked from the session. To prevent it
// I used $this->passedArgs['page']. When I clik the page paginator it will return
// current number page, but it will be empty if we click dropdown.
if (!empty($this->passedArgs['page']) {
$cat_id=$this->Session->read($this->name.'.category_id');
$filters=array('Collection.category_id' => $cat_id);
$this->set('collections', $this->paginate('Collection',$filters));
}else{
$this->set('collections', $this->paginate('Collection'));
}
}
From this case, I think that observefield will not send passedArg as we get from url such from ajax link or html->link. I hope this will usefull to anybody

Resources