Programmatically setting custom template for block
Permalink
Hello. I'm developing a custom Page list. This page list displays news from website. The news page has a gallery (Image Slider block). I need to display this Gallery block inside my custom Page list. This is easy. The catch is that I need to display this Gallery block in different theme than it is displayed on the original News page.
This code renders the Gallery block, but with default template. I thought that I could call this function as follows:
but this resets my template globally so homepageTemplate.php will now be displayed on the original page too -- and I need to use homepageTemplate.php only when calling it programmatically with my custom Page list.
foreach ($pages as $page) { $blocks = $page->getBlocks('Gallery'); $galleryBlock = $blocks[0]; $galleryBlock->display(); }
This code renders the Gallery block, but with default template. I thought that I could call this function as follows:
$galleryBlock->setCustomTemplate( "homepageTemplate.php" );
but this resets my template globally so homepageTemplate.php will now be displayed on the original page too -- and I need to use homepageTemplate.php only when calling it programmatically with my custom Page list.
This is a sample code for inserting a block manually into a page:
Thank you. However I don't need to create a new block. I need to display an already set block -- to call an instance of a block which already has data (images).
Or how should I connect my $galleryBlock (instance of gallery) to a new blocktype like you suggested?
Or how should I connect my $galleryBlock (instance of gallery) to a new blocktype like you suggested?
Hello GetSchwifty,
The display method accepts a view. Wich is passed to the render method. It does not matter how the template is created.
- block/templates/templatename.php
- block/templates/templatename/view.php
You can see this in the core code. If you are using a debugger like Xdebug you can see this more easily because you can jump into function calls.
The display method accepts a view. Wich is passed to the render method. It does not matter how the template is created.
- block/templates/templatename.php
- block/templates/templatename/view.php
$galleryBlock->display('templates/templatename');
You can see this in the core code. If you are using a debugger like Xdebug you can see this more easily because you can jump into function calls.
public function display($view = 'view') { if ($this->getBlockTypeID() < 1) { return; } $bv = new BlockView($this); $bv->render($view); }
Thank you for your reply. However this does not work for me. I tried
and nothing works, the block renders with default template. My custom Image slider is in /application/blocks/image_slider and template is in /application/blocks/image_slider/templates/template.php.
$galleryBlock->display( 'templates/template.php' ); $galleryBlock->display( 'templates/template' ); $galleryBlock->display( 'template.php' ); $galleryBlock->display( 'template' );
and nothing works, the block renders with default template. My custom Image slider is in /application/blocks/image_slider and template is in /application/blocks/image_slider/templates/template.php.
which specific version do you use? There is a bug in the early version of 5.7 that can be related to this.
have the same problem as GetSchwifty ... I also tried
also tried all teh same formats with
Did anyone every figure out how to get this working?
search/templates/jw_cloud/view.php search/templates/jw_cloud
also tried all teh same formats with
$tagcloudBlock->setCustomTemplate( "..." );
Did anyone every figure out how to get this working?
just an FYI, the setCustomTemplate problem turns out to be something quite unexpected
The code is crashing because the bID is returning null
Here is my testcase
The problem is setCustomTemplate calls updateBlockInformation and the later expect there to be a bID
Anyone have any insights as to why the bID is never returned?
The code is crashing because the bID is returning null
Here is my testcase
The problem is setCustomTemplate calls updateBlockInformation and the later expect there to be a bID
$v = [$bName, $bFilename, $dt, $tcBlock->getBlockID()];
Anyone have any insights as to why the bID is never returned?