correct practice for including files in blocks

Permalink
Hi, I am trying to include a php file into a block's view file. Something similar to how single pages work.

What is the best way to achieve this?
Thanks,
mikey

mikeyt55
 
RobertJNL replied on at Permalink Reply
RobertJNL
Hi Mikey,

within your block folder you make a /images folder.
Then use something like;
<?php echo $this->getBlockURL()?>/images/yourimage.jpg


Robert
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
If its in the block directory and mostly view/presentation stuff included from the view or edit (not the controller), use $this->inc(relative_path_from_controller).
You can see many examples of that where add and edit dialogs share a form.

You can also make it a package element and do Loader::packageElement.
mikeyt55 replied on at Permalink Reply
mikeyt55
Hi John,
having a weird issue with the $this->inc().

im doing the following:
$this->inc('folder/filename.php', $args)

and with that file im using the key name as the variable.
$args = array( 
        'arg1' => 'val1',
        'arg2' => 'val2', 
        'arg3' => 'val3',
        'arg4' => 'val4'
 );

however arg2 and 3 don't seem to work in the file.
just displaying them does nothing.
is there a limit to how many I can have? seem a little silly if there is.
JohntheFish replied on at Permalink Reply
JohntheFish
I think $this->inc() propagates the scope in a block view. I have never used it with $args.

Elements need $args, which is how I tend to build such complex views because elements can be individually overridden. With $this->inc() any override needs to repeat every component.
jordanlev replied on at Permalink Reply
jordanlev
The code you have should be working, and there is no limit to the number of $args you can pass to a file via $this->inc(). That is strange that you're getting errors, I am guessing it's due to something else (perhaps the values are not what you think they are? You can put this in the included file to see what vars it has available:

(although that will give you a HUGE amount of stuff ... if you just want to see if your vars exist at all, do this:


Good luck!

-Jordan