How can I create a template only for slideshow ? I would like to have a basic template to consult the page and an another template to consult nodes with slideshow.
How can I create a template only for slideshow ? I would like to have a basic template to consult the page and an another template to consult nodes with slideshow.
Comments
Comment #1
udig commentedHi,
Nice idea. Currently the ajax slideshow uses the exact same appearance (hence template) of the node as it normally appears. It is an interesting idea though to allow such a feature.
In general this means that we need to identify the context on which the node is shown.
Possible alternatives:
a. css level - if the changes you are after are design-related rather than structural, you may identify that the node appears within the ajax slideshow context by:
.ajax_slideshow .nodeb. template level - at the template.php you need to add theme_preprocess_node(&$vars) function (if its not there already). In that function you need to identify the context on which the node is being shown. This can be done by checking $_GET['q'] contents (assuming you use the page view). When inside the ajax slideshow context a new template file should be set e.g.
$vars['template_files'][] = 'node-in-slideshow';create the template node-in-slideshow.tpl.php and build it whichever way you like.
Additional thoughts are most welcome.
Comment #2
gabs77 commentedHi,
At the template.php, I add :
function MY_THEME_preprocess_node(&$vars){
if($vars['type'] == 'story')
$vars['template_files'][] = 'node-in-slideshow';
}
I can the different template but how do you affect this template only slideshow bloc.
Because it affects every story node too, not only in the slideshow.
Best Regards
Comment #3
udig commentedHey gabs77,
All you need to do is to change your condition. instead of:
if($vars['type'] == 'story')try using
if($_GET['q'] == 'slideshow-front')I did not try this code myself but it's a hint for the direction to take.
$_GET['q'] provides you the requested URL. whenever you are in the slideshow context you want to use different template.
Comment #4
gabs77 commentedHi udig,
I try your idea and it doesn't work but I analyse the result from $_GET['q'] and I can see that it returns "photos/get/photos/[nid]" so I think that the best method to affect a template only in slideshow block :
if(strpos($_GET['q'], '/get/photos/')!== FALSE)
$vars['template_files'][] = 'node-in-slideshow';
Regards
Comment #5
udig commentedindeed - I forgot the ajax piece.
Great to see that its working for you.
Comment #6
pietro.a commentedThis is great, and it works.
Now, suppose that I also have some imagefield content attached to the content types selected by the View that ajax_slideshow uses; and suppose that the imagecache preset for "Full nodes" is called "large", while I want to use an imagecache preset called "small" in the ajax_slideshow, instead. Could anybody help me find a way to modify my node-in-slideshow.tpl.php? Or at least a way to select "Teaser" view for ajax_slideshow's, instead of "Full node"?
I know this might not be the right place for asking this, but I would be grateful if you could address me to a better place.
thanks in advance.
Comment #7
udig commentedHi pietro.a
Indeed this question is not related to the ajax_slideshow module but the answer is quite straight-forward so...
The way to work this out is by:
1. a direct call to the theme function. In this case you will be calling the theme function aimed towards the imagecache module with the preset name and the imagefield pointer. It will look similar to this:
$vars['image'] = theme('imagecache', 'small', $node->$field_imagefield_name[0]['filepath']);This line should be placed right inside the theme_preprocess_node function. If you use a dedicated tpl for your ajax_slideshow node as discussed above, place this line within the consequent section of the 'if' statement (i.e. whenever its true this line should be executed)
2. Now go to the node tpl and place your image wherever you want by
<?php print $image?>Enjoy
Comment #8
pietro.a commentedThank you so much, your hints were very useful.
I just note that, to make it work, i had to add
<? print theme('imagecache', 'small', $field_my-image[0]['filepath']); ?>directly to the ajax_slideshow's tpl file (not in template.php's "if" statement within the node preprocess function).
I get a correct imagecache path, missing the imagefield path (i.e., the name of the image).
Might it be that $field_my-image[0]['filepath'] (or $node->$field_my-image[0]['filepath']) is not defined yet when the preprocess function is executed?
Comment #9
udig commentedTo me the above hypothesis, doesn't make sense.
I'd insist on adding it at the template.php since the tpl should not really handle any content massaging (only setting up the structure).
Did you try
dpm($node);You need the devel module to be active + permission to see its outputs for DPM to work.
check what exactly is it that you have inside the node when you're in the preprocess function.
Comment #10
fourmi4x commentedHi,
I added :
to my template.php file, and then created the page-node-slides.tpl.php file and modified it.
The modifications work fine when I load the nodes of the "slides" content type, but in the slideshow, I still see the full classical node of my main page/node.tpl.php...
Do I need to add or change something ? Many thanks ! (I'm not much of a programmer...)
Comment #11
udig commentedfourmi4x,
I am not sure what is it that you are trying to achieve. if you are after having a different template for the node when it appears within the slideshow context then follow comments 2+3+4 (you need to use the node preprocess function rather then the page preprocess)
The piece of code you added seem to provide functionality that Drupal core already supports see this page under template suggestions -> node.
...but then maybe I did not follow your motivation right.
Comment #12
fourmi4x commentedThank you udig for your answer, you understood perfectly my problem(s) !
I was really confused and didn't notice the difference between the 2 preprocess functions...
But now everything is working fine by using the code of #2, and deleting the piece of code I wrote which is obviously obsolete now :)
Many thanks again.
Comment #13
udig commented