Output HTML before blocks

Permalink 1 user found helpful
Hello,

Is there a way in a block controller file to output html code before and after the block is rendered..?

For my scenario this cannot be done in the view.php file, it has to be done from the controller.

Any guidance appreciated..?

 
keeasti replied on at Permalink Reply
keeasti
Can you give an example of what you want to achieve?
obaudains replied on at Permalink Reply
Yes ok:
I want to be able to have code before and after the lines that I can state from the controller.
Similar to on before render function but just before and just after the block.




Code out put before the block view.php file is rendered here....

-------
View.php file data output here
-------
Code output after the blocks view.php
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
You could try rendering the view manually from the view() method of the block controller, placing your code about that. I don't know if it would also be necessary or how to prevent the regular view from running.

(edit) Thinking about this more, you could write a block template that:
a) called back to the controller to get the before html
b) displayed the existing view template
c) called back to the controller to get the after html
(end edit)

Jordanlev put together a pull request on c5 Github for an easy way of creating block wrappers, so that could be worth a look.
https://github.com/concrete5/concrete5/pull/691...

Another approach could be to set aspects of the block design from within the block controller.

Or maybe you could render the block from within another block, and have the other block create the wrapper. A bit like a custom stack displayer that wrapped the stack (I am thinking along those lines because that is what I do with my Universal Content Puller addon).
obaudains replied on at Permalink Reply
Hi John,

thank you for your direction. I have managed to sort it. As an experienced c5 user a have run int s slightly different problem that you may be able to pass on some direction for.

The block is now being output which is great. I have a custom page attribute (image/file) which outputs without issue using the following code:

$ih = Loader::helper('image');
$img = $page->getAttribute('boat_main_image'); // Grab the image
 if(isset($img)) { // Make sure you have an image
         $thumb = $ih->getThumbnail($img, 100, 9999, false); // Create the thumbnail
 } 
if(isset($thumb)) {
     <img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />
}


If i edit the page attribute and assign an image asbout 1mb, it displays fine, however if i edit the page attribute and assign an image of about 3 mb, the page stopes rendering where the above code is placed.

There is nothing wrong with the image file and i have tested multiple ones. Is there an issue or limitation with c5's getThumbnail() function..?

Thanks
JohntheFish replied on at Permalink Reply
JohntheFish
I seem to remember hearing about a similar issue in the past. Maybe you can find it by googling back through the forums or bug reports.

You could also look at your php and apache error logs.

At a guess you may be running into php memory or execution limits. If so, increasing the resources available to php may be a solution (Very tentative 'may' here).
goutnet replied on at Permalink Reply
This is probably coming from the time limit on your PHP script execution time. I replied to that in another thread.
obaudains replied on at Permalink Reply
John / Goutnet,

Thank you both for your replies. I have explored this previously and have increased the max_execution_time value up to 90 seconds.

This has had no effect and the page stops rendering without an eror message at the start of the output thumbnail script.

I am quite confused as I have used c5 regularly and it has always done me proud. On this occasion i am stumped.

Would there be any other reason you can think of..?
JohntheFish replied on at Permalink Reply
JohntheFish
Maybe there will be an error message in the php or apache error logs.

Also, in C5, make sure the debug setting is to report errors (enter debug in the dashboard search).
obaudains replied on at Permalink Reply
Thanks John,

Yes debug is enabled.
Also i have checked the logs & apache logs and there are no entries.

Im totally lost...
obaudains replied on at Permalink Reply
Hi John,
Still getting nowhere. If i send you through a link and the code to the file would you be able to give it a once over please..?

Sorry to ask but i have no solutions...?
mnakalay replied on at Permalink Reply
mnakalay
Hello,

could you tell us the original width and height of your 3Mo picture?
Depending on that, the fact that you are trying to output a thumbnail with a height of 9999 might be the origin of the problem.
obaudains replied on at Permalink Reply
The pictures dimensions are 4000px x 30000px.

I have tried changing the thumbnail dimensions to a range of values (e.g. 200, 100) and the issue still persists..?
JohntheFish replied on at Permalink Reply
JohntheFish
I can't think of any regular web page software that wouldn't puke at those dimensions (doing that in PhotoShop on my desktop that is optimised for it would suffer some indigestion)

If you have your own servers, maybe design a server batch process that reads a queue set up by the web site, resizes, and writes back to somewhere the site can then import with a scheduled job. That way the resizing is done outside of the actual web server software.

Otherwise, train your users to upload a smaller copy for thumbnailing and web display.
obaudains replied on at Permalink Reply
Hi John,

Thank you for your response.

In relation to your comment, is there a setting (or method) in c5 that will allow me to set the system to resize any file uploaded through the file manager (inc bulk upload feature)..?
JohntheFish replied on at Permalink Reply
JohntheFish
I don't know of any c5 setting for that.

My Front End File Uploader has an option to resize on upload (ie before it is imported into the filemanager), but I expect it would also fail with images that big because it uses the same library calls to do the resizing.
keeasti replied on at Permalink Reply
keeasti
Sorry ... I have only achieved this only in view.php.
I should have read your post more carefully :)
Hopefully someone else can help!
nicodegunst replied on at Permalink Reply
Hi, found your post when I ran into the same problem. Increasing the memory_limit fixed it for me.
IE. add "ini_set('memory_limit', '128M');" to your view.php