R.Kinkeris Posted April 7, 2013 Share Posted April 7, 2013 (edited) Hello, I can't figure out how to do it. For example - I have a gallery module and on the gallery page the tpl files creates img lists with this code: {if $images} <h2>{l s='Images' mod='azgallery'}</h2> {assign var='nbItemsPerLine' value=3} <ul id="image_list" class="gallery_list"> {foreach from=$images item=item name=images} <li class="{if $smarty.foreach.images.index%$nbItemsPerLine==0}first-item span4{else}item span4 {/if}"> <a title="{$item.caption}" rel="lightbox" href="{$gallery_dir}images/{$item.id_image}-thickbox_default.jpg" class="lightboxTrigger"> <img src="{$gallery_dir}images/{$item.id_image}-large_default.jpg"></a> <p class="caption">{$item.caption}</p> </li> {/foreach} <br class="clear"> </ul> {/if} So when I copy the same line in different tpl file which isn't related to that module, it doesn't understand lines like {foreach from=$images item=item name=images} etc. So any ides what kind of files or links I have to include so the non-related tpl understands them? Edited April 9, 2013 by R.Kinkeris (see edit history) Link to comment Share on other sites More sharing options...
razaro Posted April 7, 2013 Share Posted April 7, 2013 So when I copy the same line in different tpl file which isn't related to that module, it doesn't understand lines like {foreach from=$images item=item name=images} etc. So any ides what kind of files or links I have to include so the non-related tpl understands them? It does not understand those lines because variable $images is not defined in files(controllers) that are connected with those other tpl files. If you check gallery.php you will probably find code that takes same data from database and then make array of images that is passed to tpl file as variable $images. Link to comment Share on other sites More sharing options...
R.Kinkeris Posted April 7, 2013 Author Share Posted April 7, 2013 In gallery.php there is a line $this->setTemplate('gallery.tpl'); I assume thats the one which assigns the variables to the gallery. So how should I edit it so the variables would also be assigned to different tpl file? Link to comment Share on other sites More sharing options...
razaro Posted April 7, 2013 Share Posted April 7, 2013 That just call template file gallery.tpl, but for variables there must be some other code. For example in ProductContraoller.php you have $images = $this->product->getImages((int)$this->context->cookie->id_lang); $product_images = array(); foreach ($images as $k => $image) { if ($image['cover']) { $this->context->smarty->assign('mainImage', $images[0]); $cover = $image; $cover['id_image'] = (Configuration::get('PS_LEGACY_IMAGES') ? ($this->product->id.'-'.$image['id_image']) : $image['id_image']); $cover['id_image_only'] = (int)$image['id_image']; } $product_images[(int)$image['id_image']] = $image; } . . . if (count($product_images)) $this->context->smarty->assign('images', $product_images); So here is $product_images assigned to variable images that will be used in product.tpl file. And to use it on different page, well that depends on where you what to add that gallery. Maybe you could use some of existing hooks and add gallery. Or you can override some controller... Link to comment Share on other sites More sharing options...
R.Kinkeris Posted April 7, 2013 Author Share Posted April 7, 2013 Okey, so for example if I want to use variable images in cms pages (cms.tpl) where and what should I write to override controllers? Link to comment Share on other sites More sharing options...
razaro Posted April 7, 2013 Share Posted April 7, 2013 For example create new file in your root override/controllers/front named CmsController.php And code should be something like <?php class CmsControllerCore extends CmsControllerCore { public function initContent() { $this->getGallerry(); parent::initContent(); } public function getGallerry() { // here goes code for getting images from gallery module $gallerry_images = ...; $this->context->smarty->assign('images', $gallerry_images); $this->setTemplate(_PS_MODULE_DIR_.'nameofgallerymodule/gallery.tpl'); } } Note this is not tested and you could try to follow logic from gallery.php. Link to comment Share on other sites More sharing options...
R.Kinkeris Posted April 7, 2013 Author Share Posted April 7, 2013 (edited) Ok, I'm still too weak at these things. Could you help me and note witch line is getting the images from gallery module? Here are two .php which refers to my module. Both files are attached. And this is what I'm using in cms page to fetch the images: <ul id="image_list" class="gallery_list"> {foreach from=$images item=item name=images} <li> <a href="http://91.224.13.185/velosocks.com/index.php?fc=module&module=azgallery&controller=gallery"> <img src="{$module_dir}azgallery/images/{$item.id_image}-large_default.jpg"></a> <p class="caption">{$item.caption}</p> </li> {/foreach} </ul> I would be very happy if you could help me with this. I'm newbie at these things. azgallery.php gallery.php Edited April 7, 2013 by R.Kinkeris (see edit history) Link to comment Share on other sites More sharing options...
razaro Posted April 7, 2013 Share Posted April 7, 2013 (edited) Is this paid module ? If it is you should not post files from module. Edit sorry, my bad I found it on forum. It is free. Edited April 7, 2013 by razaro (see edit history) Link to comment Share on other sites More sharing options...
R.Kinkeris Posted April 7, 2013 Author Share Posted April 7, 2013 It is not. It was a free azgallery which js file I rewrote from 0. And as I don't have almost any knowledge about php this part is hard for me Link to comment Share on other sites More sharing options...
razaro Posted April 7, 2013 Share Posted April 7, 2013 Ok here is controller, done in a bit of hurry and probably not the greatest solution. But you can start from that. <?php class CmsController extends CmsControllerCore { public function initContent() { $this->getGallery(); parent::initContent(); } public function getGallery() { include_once(_PS_MODULE_DIR_.'azgallery/azgallery.php'); $azgallery = new AzGallery; $this->context->smarty->assign(array( 'gallery_url' => _PS_BASE_URL_.__PS_BASE_URI__.'index.php?fc=module&module=azgallery&controller=gallery', 'gallery_dir' => _PS_BASE_URL_.__PS_BASE_URI__.'modules/azgallery/' )); /* List albums */ if( !isset( $_GET['id_album'] ) ) $this->context->smarty->assign('albums', $azgallery->getAlbums()); /* List images */ $this->context->smarty->assign('images', $azgallery->getImages( 1 )); if( isset( $_GET['id_album'] ) ) $this->context->smarty->assign('backhome', true); $this->setTemplate(_PS_MODULE_DIR_.'azgallery/views/templates/front/gallery.tpl'); } } and in cms.tpl <div class="rte{if $content_only} content_only{/if}"> {$cms->content} </div> <ul id="image_list" class="gallery_list"> {foreach from=$images item=item name=images} <li> <a href="#"> <img src="{$base_dir}modules/azgallery/images/{$item.id_image}-large_default.jpg" width="128" height="128"></a> <p class="caption">{$item.caption}</p> </li> {/foreach} </ul> Notice that in cms controller /* List images */ $this->context->smarty->assign('images', $azgallery->getImages( 1 )); I manually set id to 1 for first album. Also you should try to contact module developer, maybe he could be of better help. 1 Link to comment Share on other sites More sharing options...
R.Kinkeris Posted April 7, 2013 Author Share Posted April 7, 2013 Ok, thank yu very much for help. Ill try it tomorrow and post my success. Link to comment Share on other sites More sharing options...
R.Kinkeris Posted April 8, 2013 Author Share Posted April 8, 2013 (edited) I created a controller file name CmsController.php and put it in override/controllers/front But the page still doesnt understand {foreach from=$images item=item name=images} Did I put the file in right place? Edited April 8, 2013 by R.Kinkeris (see edit history) Link to comment Share on other sites More sharing options...
razaro Posted April 8, 2013 Share Posted April 8, 2013 Code I posted worked for me, but I put 1 for gallery id in $azgallery->getImages( 1) but maybe you have galleries with other id's. Link to comment Share on other sites More sharing options...
R.Kinkeris Posted April 8, 2013 Author Share Posted April 8, 2013 Well I don't use albums. I have only list of images. Maybe thats the problem? Link to comment Share on other sites More sharing options...
R.Kinkeris Posted April 9, 2013 Author Share Posted April 9, 2013 You were correct, that code works. Somehow the new controller file wasn't uploaded correctly so it didn't work for me, but ow it works perfectly. Thank you very much. Link to comment Share on other sites More sharing options...
volkovsvit Posted November 21, 2013 Share Posted November 21, 2013 Thank you very much! I also helped your advice. how to display one album on the same page, and another album on another page, created in CMS page sorry for my English Link to comment Share on other sites More sharing options...
GrandeLupo Posted April 11, 2015 Share Posted April 11, 2015 How do Random pictures in left column? Grazie! Link to comment Share on other sites More sharing options...
Recommended Posts