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
What is the best way to achieve this?
Thanks,
mikey
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.
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.
Hi John,
having a weird issue with the $this->inc().
im doing the following:
and with that file im using the key name as the variable.
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.
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.
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.
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.
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
<?php print_r(get_defined_vars()); ?>
(although that will give you a HUGE amount of stuff ... if you just want to see if your vars exist at all, do this:
<?php print_r(array_keys(get_defined_vars())); ?>
Good luck!
-Jordan
within your block folder you make a /images folder.
Then use something like;
Robert