Drupal 6 - 强制页面视图显示不同的视图?
这是一个疯狂的问题...
我有一个设置为页面的视图显示。它在主题 A(桌面)中看起来很棒,但在主题 B(移动)中看起来很糟糕。因此,我为主题 B 制作了不同版本的视图。由于桌面/移动“站点”相同,只是主题不同,因此无论选择什么主题,该页面的 url 都将相同。
因此,我希望能够将用户指向:
mysite/this_crazy_view
并让返回的页面根据其所在的主题选择正确的视图。我知道,如果我使用块,我只会将适当的块分配给页面在逐个主题的基础上有问题,但由于显示使用页面显示,我不知道正确的方法是什么。
如果我可以帮助的话,我宁愿不将视图重建为块(如果无法帮助,那就这样吧......)所以我希望有某种方法可以通过 tpl.php 文件有条件地加载视图或类似的东西...
我在模块中使用的代码(根据下面 @Clive 的建议)是:
<?php
function bandes_custom_hook_menu() {
$items['charley_test'] = array(
'title' => 'Title',
'access arguments' => array('access content'),
'page callback' => 'bandes_custom_set_page_view',
'type' => MENU_NORMAL_ITEM );
return $items;
}
function bandes_custom_set_page_view() {
global $theme_key;
$view_name = $theme_key == 'mobile_jquery' ? 'course_views_mobile' : 'course_views';
$display_id = 'page_5';
return views_embed_view($view_name, $display_id);
}
?>
我已经多次清除缓存并在 $items 数组中尝试了各种不同的路径。 course_views 和 course_views_mobile 绝对可以独立工作。
我还想知道是否可以创建一个views-view--course-views--page-5.tpl.php,其中除了views_embed_view(course_views_mobile, page_5)部分之外几乎不包含任何内容? (仅针对两个主题之一......)
实际上我认为答案比上述所有答案都简单。重定向的事情让我很舒服,所以我删除了模块,将路径重置为我一直在使用的路径,然后尝试了模板/主题方法。
这是:views-view--course-views--page-5.tpl.php,仅在移动主题上使用,但指的是非移动视图(有点让我头疼,但它有效)
<?php
//get the view
print "IM IN YR VUE, MESSING THNGZ UP!"; //yeah, I'm going to remove this part...
$view_name="course_views_mobile";
$display_id="page_5";
print views_embed_view($view_name, $display_id);
?>
任何原因不应该工作吗? (或者为什么这是一个非常糟糕的主意?)
Kind-of a crazy question here...
I have a view display that's set up as a page. It looks great in theme A (desktop), but terrible in theme B (mobile). So I made a different version of the view for theme B. Since the desktop/mobile 'sites' are the same just with different themes, the url for this page will be the same regardless of hte theme selected.
So I would like to be able to point the user to:
mysite/this_crazy_view
and have the returned page select the proper view depending on which theme it's in. I know that if I were using blocks I would just assign the appropriate blocks to the page in question on a theme-by-theme basis, but since the displays are using page display I don't know what the right approach would be.
I would rather not rebuild the views as blocks if I can help it (if it can't be helped, so be it...) so I was hoping there was some way to conditionally load the view via the tpl.php file or something like that...
The code I'm using in my module (per @Clive 's recommendation below) is:
<?php
function bandes_custom_hook_menu() {
$items['charley_test'] = array(
'title' => 'Title',
'access arguments' => array('access content'),
'page callback' => 'bandes_custom_set_page_view',
'type' => MENU_NORMAL_ITEM );
return $items;
}
function bandes_custom_set_page_view() {
global $theme_key;
$view_name = $theme_key == 'mobile_jquery' ? 'course_views_mobile' : 'course_views';
$display_id = 'page_5';
return views_embed_view($view_name, $display_id);
}
?>
I've cleared the cache a number of times and tried a variety of different paths in the $items array. The course_views and course_views_mobile both definitely work on their own.
I was also wondering if I could just create a views-view--course-views--page-5.tpl.php which contains almost nothing aside from the views_embed_view(course_views_mobile, page_5) part? (Only on one of the two themes...)
Actually I think the answer was simpler than all of the above. The redirect thing was giving me fits, so I removed the module, reset the paths to what I had been using, and tried the template/theme approach instead.
This is: views-view--course-views--page-5.tpl.php, only used on the mobile theme, but referring to the non-mobile view (kinda gives me a headache, but it works)
<?php
//get the view
print "IM IN YR VUE, MESSING THNGZ UP!"; //yeah, I'm going to remove this part...
$view_name="course_views_mobile";
$display_id="page_5";
print views_embed_view($view_name, $display_id);
?>
Any reason that shouldn't work? (Or why it is a really bad idea?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
又是我:)
实际上我只是想到了一个简单的方法来解决这个问题;如果您可以将视图的 URL 更改为您想要访问它们的路径之外的其他内容(任何路径都可以),您可以实现 hook_menu() 函数在该路径的自定义模块中,根据您的主题进行选择:
应该这样做窍门
Me again :)
I just thought of an easy-ish way around this actually; if you can change the URL of your views to something other than the path you want to access them at (any path would do) you could implement a hook_menu() function in a custom module for that path, to make the choice depending on your theme:
That should do the trick